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.
87 lines
2.3 KiB
87 lines
2.3 KiB
package conf
|
|
|
|
import (
|
|
"go_fabric/dao"
|
|
"strings"
|
|
|
|
"gopkg.in/ini.v1"
|
|
)
|
|
|
|
var (
|
|
AppModel string
|
|
HttpPort string
|
|
|
|
Db string
|
|
DbHost string
|
|
DbPort string
|
|
DbUser string
|
|
DbPassword string
|
|
DbName string
|
|
|
|
RedisDb string
|
|
RedisAddr string
|
|
RedisPw string
|
|
RedisDbName string
|
|
|
|
ValidEmail string
|
|
SmtpHost string
|
|
SmtpEmail string
|
|
SmtpPass string
|
|
|
|
Host string
|
|
ProductPath string
|
|
AvatarPath string
|
|
)
|
|
|
|
func Init() {
|
|
//从本地文件读取环境变量
|
|
file, err := ini.Load("C:/Users/801028/Desktop/marketv1.2/go_fabric/conf/config.ini")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
LoadServer(file)
|
|
LoadMySql(file)
|
|
LoadRedis(file)
|
|
LoadEmail(file)
|
|
// mysql读
|
|
LoadPhotoPath(file)
|
|
PathRead := strings.Join([]string{DbUser, ":", DbPassword, "@tcp(", DbHost, ":", DbPort, ")/", DbName, "?charset=utf8mb4&parseTime=true&loc=Local"}, "")
|
|
//写
|
|
PathWrite := strings.Join([]string{DbUser, ":", DbPassword, "@tcp(", DbHost, ":", DbPort, ")/", DbName, "?charset=utf8mb4&parseTime=true&loc=Local"}, "")
|
|
dao.Database(PathRead, PathWrite)
|
|
}
|
|
|
|
func LoadServer(file *ini.File) {
|
|
AppModel = file.Section("service").Key("AppMode").String()
|
|
HttpPort = file.Section("service").Key("HttpPort").String()
|
|
}
|
|
|
|
func LoadMySql(file *ini.File) {
|
|
Db = file.Section("mysql").Key("DB").String()
|
|
DbHost = file.Section("mysql").Key("DbHost").String()
|
|
DbPort = file.Section("mysql").Key("DbPort").String()
|
|
DbUser = file.Section("mysql").Key("DbUser").String()
|
|
DbPassword = file.Section("mysql").Key("DbPassword").String()
|
|
DbName = file.Section("mysql").Key("DbName").String()
|
|
}
|
|
|
|
func LoadRedis(file *ini.File) {
|
|
RedisDb = file.Section("redis").Key("RedisDb").String()
|
|
RedisAddr = file.Section("redis").Key("RedisAddr").String()
|
|
RedisPw = file.Section("redis").Key("RedisPw").String()
|
|
RedisDbName = file.Section("redis").Key("RedisDbName").String()
|
|
}
|
|
|
|
func LoadEmail(file *ini.File) {
|
|
ValidEmail = file.Section("email").Key("ValidEmail").String()
|
|
SmtpHost = file.Section("email").Key("SmtpHost").String()
|
|
SmtpEmail = file.Section("email").Key("SmtpEmail").String()
|
|
SmtpPass = file.Section("email").Key("SmtpPass").String()
|
|
}
|
|
|
|
func LoadPhotoPath(file *ini.File) {
|
|
Host = file.Section("path").Key("Host").String()
|
|
ProductPath = file.Section("path").Key("ProductPath").String()
|
|
AvatarPath = file.Section("path").Key("AvatarPath").String()
|
|
}
|