parent
370ee8405d
commit
53da4655ad
@ -0,0 +1,7 @@
|
|||||||
|
[Database]
|
||||||
|
Type = mysql
|
||||||
|
User = root
|
||||||
|
Password = root
|
||||||
|
Host = 127.0.0.1:3306
|
||||||
|
Name = v3
|
||||||
|
TablePrefix = v3_
|
@ -0,0 +1,45 @@
|
|||||||
|
package conf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Cloudreve/pkg/util"
|
||||||
|
"fmt"
|
||||||
|
"github.com/go-ini/ini"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Conf struct {
|
||||||
|
Database Database
|
||||||
|
}
|
||||||
|
|
||||||
|
type Database struct {
|
||||||
|
Type string
|
||||||
|
User string
|
||||||
|
Password string
|
||||||
|
Host string
|
||||||
|
Name string
|
||||||
|
TablePrefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
var database = &Database{
|
||||||
|
Type: "UNSET",
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg *ini.File
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
var err error
|
||||||
|
//TODO 配置文件不存在时创建
|
||||||
|
cfg, err = ini.Load("conf/conf.ini")
|
||||||
|
if err != nil {
|
||||||
|
util.Log().Panic("无法解析配置文件 'conf/conf.ini': ", err)
|
||||||
|
}
|
||||||
|
mapSection("Database", database)
|
||||||
|
fmt.Println(database)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapSection(section string, confStruct interface{}) {
|
||||||
|
err := cfg.Section("Database").MapTo(database)
|
||||||
|
if err != nil {
|
||||||
|
util.Log().Warning("配置文件 Database 分区解析失败")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue