48 lines
788 B
Go
48 lines
788 B
Go
package config
|
|
|
|
import (
|
|
"github.com/BurntSushi/toml"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
/********start-配置信息*********/
|
|
type Nacos struct {
|
|
NamespaceId string
|
|
Username string
|
|
Password string
|
|
IpAddr string
|
|
DataId string
|
|
Group string
|
|
}
|
|
|
|
type AliConfig struct {
|
|
System System `toml:"system"`
|
|
Nacos Nacos `toml:"Nacos"`
|
|
}
|
|
|
|
/********start-配置信息*********/
|
|
|
|
var AliAppConfig *AliConfig
|
|
|
|
func newAliConfig() *AliConfig {
|
|
return new(AliConfig)
|
|
}
|
|
|
|
func LoadAliEnv(path string) (*AliConfig, error) {
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
configStr := os.ExpandEnv(string(data))
|
|
|
|
AliAppConfig = newAliConfig()
|
|
|
|
if _, err := toml.Decode(configStr, AliAppConfig); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return AliAppConfig, nil
|
|
}
|