109 lines
1.8 KiB
Go
109 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"fonchain-fiee/pkg/common"
|
|
"github.com/BurntSushi/toml"
|
|
"gopkg.in/ini.v1"
|
|
"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
|
|
}
|
|
func GetOptions() {
|
|
iniConf, err := common.GetConf()
|
|
if err != nil {
|
|
panic("iniConf error")
|
|
}
|
|
file, err := ini.Load(iniConf)
|
|
if err != nil {
|
|
fmt.Println("服务器配置文件读取错误,请检查文件路径:", err)
|
|
}
|
|
LoadServer(file)
|
|
}
|
|
func LoadServer(file *ini.File) {
|
|
|
|
}
|