fonchain-fiee/cmd/config/config.go

93 lines
1.5 KiB
Go
Raw Normal View History

2025-02-20 08:24:49 +00:00
package config
import (
"errors"
"fmt"
"github.com/BurntSushi/toml"
"os"
)
/********start-配置信息*********/
//Baiduco 百度上链
type Mysql struct {
Db string
DbHost string
DbPort string
DbUser string
DbPassWord string
DbName string
}
type Redis struct {
RedisDB string
RedisAddr string
RedisPW string
RedisDBNAme string
}
type System struct {
Mode string
Version string
HttpPort string
Host string
RedirectUri string
}
type Mobile struct {
SK string
AK string
URL string
DingDingKey string
}
type Ai struct {
Host string
TelNum string
Password string
}
type Config struct {
Mysql Mysql `toml:"mysql"`
Redis Redis `toml:"redis"`
System System `toml:"system"`
Mobile Mobile `toml:"mobile"`
Ai Ai `toml:"ai"`
}
/********start-配置信息*********/
var AppConfig *Config
func newConfig() *Config {
return new(Config)
}
func LoadEnv(path string) (*Config, error) {
_, err := os.Stat(path)
if err != nil {
return nil, err
}
AppConfig = newConfig()
if _, err := toml.DecodeFile(path, AppConfig); err != nil {
return nil, err
}
return AppConfig, nil
}
func LoadEnvFromFileInfo(data string) (*Config, error) {
fmt.Println(data)
if data == "" {
return nil, errors.New("nacos 配置文件为空")
}
AppConfig = newConfig()
if _, err := toml.Decode(data, AppConfig); err != nil {
return nil, err
}
return AppConfig, nil
}