1Panel/backend/configs/sqlite.go

26 lines
566 B
Go
Raw Normal View History

2022-08-16 15:30:23 +00:00
package configs
2022-11-16 10:27:22 +00:00
import (
"fmt"
"os"
)
2022-08-16 15:30:23 +00:00
type Sqlite struct {
2022-11-16 10:27:22 +00:00
Path string `mapstructure:"path"`
DbFile string `mapstructure:"db_file"`
2022-08-16 15:30:23 +00:00
}
func (s *Sqlite) Dsn() string {
2022-11-16 10:27:22 +00:00
if _, err := os.Stat(s.Path); err != nil {
if err := os.MkdirAll(s.Path, os.ModePerm); err != nil {
panic(fmt.Errorf("init db dir falied, err: %v", err))
}
}
if _, err := os.Stat(s.Path + "/" + s.DbFile); err != nil {
if _, err := os.Create(s.Path + "/" + s.DbFile); err != nil {
panic(fmt.Errorf("init db file falied, err: %v", err))
}
}
2022-08-16 15:30:23 +00:00
return s.Path + "/" + s.DbFile
}