Restructure

重构
This commit is contained in:
谢小军
2019-09-30 18:25:22 +08:00
parent 7a555e91f5
commit ee2e02092a
18 changed files with 249 additions and 247 deletions

View File

@@ -2,7 +2,7 @@ package config
import "fmt"
//Config .
// Config custom config struct
type Config struct {
CfgBase
MySQLInfo MysqlDbInfo `toml:"mysql_info"`
@@ -12,26 +12,26 @@ type Config struct {
SingularTable bool `toml:"singular_table"`
}
//MysqlDbInfo mysql 数据库信息
// MysqlDbInfo mysql database information. mysql 数据库信息
type MysqlDbInfo struct {
Host string `validate:"required"` //地址
Port int `validate:"required"` //端口号
Username string `validate:"required"` //用户名
Password string `validate:"required"` //密码
Database string `validate:"required"` //数据库名
Host string `validate:"required"` // Host. 地址
Port int `validate:"required"` // Port 端口号
Username string `validate:"required"` // Username 用户名
Password string `validate:"required"` // Password 密码
Database string `validate:"required"` // Database 数据库名
}
//SetMysqlDbInfo 更新mysql配置信息
// SetMysqlDbInfo Update MySQL configuration information
func SetMysqlDbInfo(info *MysqlDbInfo) {
_map.MySQLInfo = *info
}
//GetMysqlDbInfo 获取mysql配置信息
// GetMysqlDbInfo Get MySQL configuration information .获取mysql配置信息
func GetMysqlDbInfo() MysqlDbInfo {
return _map.MySQLInfo
}
//GetMysqlConStr 获取mysql 连接字符串
// GetMysqlConStr Get MySQL connection string.获取mysql 连接字符串
func GetMysqlConStr() string {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
_map.MySQLInfo.Username,
@@ -42,32 +42,32 @@ func GetMysqlConStr() string {
)
}
//SetOutDir 设置输出目录
// SetOutDir Setting Output Directory.设置输出目录
func SetOutDir(outDir string) {
_map.OutDir = outDir
}
//GetOutDir 获取输出目录
// GetOutDir Get Output Directory.获取输出目录
func GetOutDir() string {
return _map.OutDir
}
//SetSingularTable 设置禁用表名复数
// SetSingularTable Set Disabled Table Name Plurals.设置禁用表名复数
func SetSingularTable(b bool) {
_map.SingularTable = b
}
//GetSingularTable 获取禁用表名复数
// GetSingularTable Get Disabled Table Name Plurals.获取禁用表名复数
func GetSingularTable() bool {
return _map.SingularTable
}
//GetSimple 简单输出
// GetSimple simple output.简单输出
func GetSimple() bool {
return _map.Simple
}
//GetIsJSONTag json标记
// GetIsJSONTag json tag.json标记
func GetIsJSONTag() bool {
return _map.IsJSONTag
}

View File

@@ -9,13 +9,13 @@ import (
"github.com/BurntSushi/toml"
)
//CfgBase .
// CfgBase base config struct
type CfgBase struct {
SerialNumber string `json:"serial_number" toml:"serial_number"` //版本号
ServiceName string `json:"service_name" toml:"service_name"` //service名字
ServiceDisplayname string `json:"service_displayname" toml:"service_displayname"` //显示名
SerciceDesc string `json:"sercice_desc" toml:"sercice_desc"` //service描述
IsDev bool `json:"is_dev" toml:"is_dev"` //是否是开发版本
SerialNumber string `json:"serial_number" toml:"serial_number"` // version.版本号
ServiceName string `json:"service_name" toml:"service_name"` // service name .service名字
ServiceDisplayname string `json:"service_displayname" toml:"service_displayname"` // display name .显示名
SerciceDesc string `json:"sercice_desc" toml:"sercice_desc"` // sercice desc .service描述
IsDev bool `json:"is_dev" toml:"is_dev"` // Is it a development version?是否是开发版本
}
var _map = Config{}
@@ -34,7 +34,7 @@ func onInit() {
}
}
//InitFile ...
// InitFile default value from file .
func InitFile(filename string) error {
if _, err := toml.DecodeFile(filename, &_map); err != nil {
fmt.Println("read toml error: ", err.Error())
@@ -44,7 +44,7 @@ func InitFile(filename string) error {
return nil
}
//GetServiceConfig 获取service配置信息
// GetServiceConfig Get service configuration information
func GetServiceConfig() (name, displayName, desc string) {
name = _map.ServiceName
displayName = _map.ServiceDisplayname

View File

@@ -10,7 +10,7 @@ const (
`
)
//IsRunTesting 判断是否在测试环境下使用
// IsRunTesting Determine whether to use it in a test environment.判断是否在测试环境下使用
func IsRunTesting() bool {
if len(os.Args) > 1 {
return strings.HasPrefix(os.Args[1], "-test")