init
This commit is contained in:
31
config/readConfig.go
Normal file
31
config/readConfig.go
Normal file
@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import "github.com/BurntSushi/toml"
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `toml:"server"`
|
||||
DB DBConfig `toml:"db"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port int `toml:"port"`
|
||||
}
|
||||
|
||||
type DBConfig struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
Database string `toml:"database"`
|
||||
User string `toml:"user"`
|
||||
Passwd string `toml:"passwd"`
|
||||
}
|
||||
|
||||
var Conf *Config
|
||||
|
||||
func ReadConfig(path string) error {
|
||||
var c Config
|
||||
if _, err := toml.DecodeFile(path, &c); err != nil {
|
||||
return err
|
||||
}
|
||||
Conf = &c
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user