配置文件
定义
在项目config目录下定义每个配置文件
mysql配置文件config/mysql.go
package config
const (
MysqlHostName = "127.0.0.1"
MysqlDb = "dbname"
MysqlUser = "root"
MysqlPassWord = "root"
MysqlCharSet = "utf8"
MysqlPrefix = "go_"
)
redis配置文件config/redis.go
package config
const (
RedisAddr = "127.0.0.1:6379"
RedisPassWord = ""
RedisDb = 0
RedisPoolSize = 30
RedisMinIdleConns = 30
)
返回状态码配置文件config/responseCode.go
package config
const (
Ok = 200
Error = 500
Logout = 600
)
使用
在需要使用的地方引入config包
import "project/config"
config.Ok