diff --git a/pkg/database/init.go b/pkg/database/init.go index f96fa9f..915f279 100644 --- a/pkg/database/init.go +++ b/pkg/database/init.go @@ -2,6 +2,7 @@ package database import ( "fmt" + "gorm.io/driver/postgres" "gorm.io/gorm" ) diff --git a/pkg/database/options.go b/pkg/database/options.go index bc13ef3..7541a40 100644 --- a/pkg/database/options.go +++ b/pkg/database/options.go @@ -1,5 +1,11 @@ package database +import ( + "os" + + "gopkg.in/yaml.v3" +) + type DBOption struct { Host string `yaml:"host"` User string `yaml:"user"` @@ -7,3 +13,18 @@ type DBOption struct { Port string `yaml:"port"` DBName string `yaml:"dbname"` } + +const ( + // 默认的数据库配置文件路径 + DefaultConfigPath = "/cfg/db.yaml" +) + +func LoadDBConfig(path string) (*DBOption, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + var opt DBOption + return &opt, yaml.NewDecoder(f).Decode(&opt) +}