health-go/config/readConfig.go

40 lines
733 B
Go
Raw Permalink Normal View History

2024-10-17 23:52:10 +08:00
package config
import "github.com/BurntSushi/toml"
type Config struct {
Server ServerConfig `toml:"server"`
DB DBConfig `toml:"db"`
2024-10-28 14:41:27 +08:00
Redis RedisConfig `toml:"redis"`
2024-10-17 23:52:10 +08:00
}
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"`
}
2024-10-28 14:41:27 +08:00
type RedisConfig struct {
Host string `toml:"host"`
Port int `toml:"port"`
DB int `toml:"db"`
Passwd string `toml:"passwd"`
}
2024-10-17 23:52:10 +08:00
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
}