You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
4.8 KiB
214 lines
4.8 KiB
package ConfigUtil
|
|
|
|
import (
|
|
"fmt"
|
|
"gopkg.in/ini.v1"
|
|
"os"
|
|
)
|
|
|
|
var (
|
|
//要发布到的主机信息
|
|
DistributeIp string
|
|
DistributePort int32
|
|
DistributeUser string
|
|
DistributePwd string
|
|
DistributeRemotePath string
|
|
DistributeLocalPath string
|
|
|
|
//服务器的端口
|
|
ServerPort string
|
|
|
|
//项目名称
|
|
ProjectName string
|
|
|
|
//mysql配置
|
|
MysqlIp string
|
|
MysqlPort string
|
|
MysqlDbName string
|
|
MysqlUser string
|
|
MysqlPwd string
|
|
|
|
//REDIS配置
|
|
RedisIp string
|
|
RedisPort string
|
|
RedisDb string
|
|
|
|
//minio
|
|
MinioEndPoint string
|
|
MinioAccessKeyId string
|
|
MinioSecretAccessKey string
|
|
MinioBucket string
|
|
MinioDownloadPrefix string
|
|
|
|
//obs
|
|
ObsEndPoint string
|
|
ObsAccessKeyId string
|
|
ObsSecretAccessKey string
|
|
ObsBucket string
|
|
|
|
//preview
|
|
PreviewPrefix string
|
|
|
|
SavePath string
|
|
|
|
//融云配置文件位置
|
|
RongYunConfigPath string
|
|
|
|
//SSDB
|
|
SSDBIp string
|
|
SSDBPort int
|
|
|
|
//elasticsearch配置
|
|
ESUrl string
|
|
)
|
|
|
|
//cookie中的SessionId名称
|
|
var SessionId = "ds_sso_sessionid"
|
|
|
|
//登录名到会话ID的前缀
|
|
var SearchSessionIdPrefix = "ds_sso_search_session_"
|
|
|
|
// 判断所给路径文件/文件夹是否存在
|
|
func Exists(path string) bool {
|
|
_, err := os.Stat(path) //os.Stat获取文件信息
|
|
if err != nil {
|
|
if os.IsExist(err) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
func init() {
|
|
//判断是不是单元测试,如果是的话,那么配置文件的路径需要加上一个.
|
|
var configIniFile = "./Config/Config.ini"
|
|
//判断文件不是存在
|
|
if !Exists(configIniFile) {
|
|
configIniFile = "." + configIniFile
|
|
}
|
|
|
|
iniParser := IniParser{}
|
|
if err := iniParser.Load(configIniFile); err != nil {
|
|
fmt.Printf("try load config file[%s] error[%s]\n", configIniFile, err.Error())
|
|
return
|
|
}
|
|
|
|
//要发布到的主机信息
|
|
DistributeIp = iniParser.GetString("distribute", "ip")
|
|
DistributePort = iniParser.GetInt32("distribute", "port")
|
|
DistributeUser = iniParser.GetString("distribute", "user")
|
|
DistributePwd = iniParser.GetString("distribute", "pwd")
|
|
DistributeRemotePath = iniParser.GetString("distribute", "remotePath")
|
|
DistributeLocalPath = iniParser.GetString("distribute", "localPath")
|
|
|
|
//服务器的端口
|
|
ServerPort = iniParser.GetString("server", "port")
|
|
|
|
//项目名称
|
|
ProjectName = iniParser.GetString("project", "project_name")
|
|
|
|
//mysql
|
|
MysqlIp = iniParser.GetString("mysql", "ip")
|
|
MysqlPort = iniParser.GetString("mysql", "port")
|
|
MysqlDbName = iniParser.GetString("mysql", "db_name")
|
|
MysqlUser = iniParser.GetString("mysql", "user")
|
|
MysqlPwd = iniParser.GetString("mysql", "pwd")
|
|
|
|
//Redis
|
|
RedisIp = iniParser.GetString("redis", "ip")
|
|
RedisPort = iniParser.GetString("redis", "port")
|
|
RedisDb = iniParser.GetString("redis", "db")
|
|
|
|
//minio
|
|
MinioEndPoint = iniParser.GetString("minio", "minio_endpoint")
|
|
MinioAccessKeyId = iniParser.GetString("minio", "minio_accessKeyId")
|
|
MinioSecretAccessKey = iniParser.GetString("minio", "minio_secretAccessKey")
|
|
MinioBucket = iniParser.GetString("minio", "minio_bucket")
|
|
MinioDownloadPrefix = iniParser.GetString("minio", "download_prefix")
|
|
|
|
//obs
|
|
ObsEndPoint = iniParser.GetString("obs", "obs_endpoint")
|
|
ObsAccessKeyId = iniParser.GetString("obs", "obs_accessKeyId")
|
|
ObsSecretAccessKey = iniParser.GetString("obs", "obs_secretAccessKey")
|
|
ObsBucket = iniParser.GetString("obs", "obs_bucket")
|
|
|
|
//预览前缀
|
|
PreviewPrefix = iniParser.GetString("preview", "prefix")
|
|
|
|
//保存路径
|
|
SavePath = iniParser.GetString("savePath", "path")
|
|
|
|
//融云配置文件位置
|
|
RongYunConfigPath = iniParser.GetString("rongyun", "config_path")
|
|
|
|
//SSDB
|
|
SSDBIp = iniParser.GetString("ssdb", "ip")
|
|
SSDBPort = iniParser.GetInt("ssdb", "port")
|
|
|
|
//elasticsearch
|
|
ESUrl = iniParser.GetString("elasticsearch", "url")
|
|
}
|
|
|
|
type IniParser struct {
|
|
confReader *ini.File // config reader
|
|
}
|
|
|
|
type IniParserError struct {
|
|
errorInfo string
|
|
}
|
|
|
|
func (e *IniParserError) Error() string { return e.errorInfo }
|
|
|
|
func (this *IniParser) Load(configFileName string) error {
|
|
conf, err := ini.Load(configFileName)
|
|
if err != nil {
|
|
this.confReader = nil
|
|
return err
|
|
}
|
|
this.confReader = conf
|
|
return nil
|
|
}
|
|
|
|
func (this *IniParser) GetString(section string, key string) string {
|
|
if this.confReader == nil {
|
|
return ""
|
|
}
|
|
|
|
s := this.confReader.Section(section)
|
|
if s == nil {
|
|
return ""
|
|
}
|
|
|
|
return s.Key(key).String()
|
|
}
|
|
|
|
func (this *IniParser) GetInt32(section string, key string) int32 {
|
|
if this.confReader == nil {
|
|
return 0
|
|
}
|
|
|
|
s := this.confReader.Section(section)
|
|
if s == nil {
|
|
return 0
|
|
}
|
|
|
|
valueInt, _ := s.Key(key).Int()
|
|
|
|
return int32(valueInt)
|
|
}
|
|
|
|
func (this *IniParser) GetInt(section string, key string) int {
|
|
if this.confReader == nil {
|
|
return 0
|
|
}
|
|
|
|
s := this.confReader.Section(section)
|
|
if s == nil {
|
|
return 0
|
|
}
|
|
|
|
valueInt, _ := s.Key(key).Int()
|
|
|
|
return int(valueInt)
|
|
}
|