mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-06 15:35:47 +08:00
简化API节点的数据库配置(db.yaml)
This commit is contained in:
25
internal/configs/db_config.go
Normal file
25
internal/configs/db_config.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package configs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LoadDBConfig() (*dbs.Config, error) {
|
||||
var config = &dbs.Config{}
|
||||
for _, filename := range []string{".db.yaml", "db.yaml"} {
|
||||
configData, err := os.ReadFile(Tea.ConfigFile(filename))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
err = yaml.Unmarshal(configData, config)
|
||||
return config, err
|
||||
}
|
||||
|
||||
return nil, errors.New("could not find database config file '.db.yaml' or 'db.yaml'")
|
||||
}
|
||||
Reference in New Issue
Block a user