mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-01-23 02:35:10 +00:00
chore: style and gofmt (#622)
Former-commit-id: 669963fd1d51d7e2d32520ffb0c1ecd5e4224c78 [formerly 8ef320b07699c842ae0325e4665d570fa4399481] [formerly d171df23332dff1d33f00a7407f5dc3f6dde1ef7 [formerly d0fd97d943]]
Former-commit-id: dc9a921b032e1acee0845186e7a009badbe768c5 [formerly 0c8a0f739bd1d984ca0db2b0623da5fdb813f4e0]
Former-commit-id: 3005cd15261952387fde1adf13770e2c1ee52749
This commit is contained in:
parent
c50a9b29bd
commit
9a54abfe62
6 changed files with 47 additions and 32 deletions
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/asdine/storm"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/filebrowser/filebrowser/v2/storage"
|
||||
"github.com/pelletier/go-toml"
|
||||
"gopkg.in/yaml.v2"
|
||||
toml "github.com/pelletier/go-toml"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type oldDefs struct {
|
||||
|
|
@ -33,7 +33,7 @@ type oldAuth struct {
|
|||
}
|
||||
|
||||
type oldConf struct {
|
||||
Port string `json:"port" yaml:"port" toml:"port"`
|
||||
Port string `json:"port" yaml:"port" toml:"port"`
|
||||
BaseURL string `json:"baseURL" yaml:"baseURL" toml:"baseURL"`
|
||||
Log string `json:"log" yaml:"log" toml:"log"`
|
||||
Address string `json:"address" yaml:"address" toml:"address"`
|
||||
|
|
@ -62,14 +62,14 @@ var defaults = &oldConf{
|
|||
},
|
||||
}
|
||||
|
||||
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
func readConf(path string) (*oldConf, error) {
|
||||
cfg := &oldConf{}
|
||||
if path != "" {
|
||||
ext := filepath.Ext(path)
|
||||
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
|
|
@ -81,23 +81,32 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
|||
case ".yaml", ".yml":
|
||||
err = yaml.NewDecoder(fd).Decode(cfg)
|
||||
default:
|
||||
return errors.New("unsupported config extension " + ext)
|
||||
return nil, errors.New("unsupported config extension " + ext)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
cfg = defaults
|
||||
path, err := filepath.Abs(".")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
cfg.Defaults.Scope = path
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
|
||||
cfg, err := readConf(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commands := map[string][]string{}
|
||||
err := db.Get("config", "commands", &commands)
|
||||
err = db.Get("config", "commands", &commands)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -109,8 +118,8 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
|||
}
|
||||
|
||||
s := &settings.Settings{
|
||||
Key: key,
|
||||
Signup: false,
|
||||
Key: key,
|
||||
Signup: false,
|
||||
Defaults: settings.UserDefaults{
|
||||
Scope: cfg.Defaults.Scope,
|
||||
Commands: cfg.Defaults.Commands,
|
||||
|
|
@ -130,10 +139,10 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
|||
}
|
||||
|
||||
server := &settings.Server{
|
||||
BaseURL : cfg.BaseURL,
|
||||
Port : cfg.Port,
|
||||
Address : cfg.Address,
|
||||
Log : cfg.Log,
|
||||
BaseURL: cfg.BaseURL,
|
||||
Port: cfg.Port,
|
||||
Address: cfg.Address,
|
||||
Log: cfg.Log,
|
||||
}
|
||||
|
||||
var auther auth.Auther
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue