123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- package config
- import (
- "github.com/Unknwon/goconfig"
- "github.com/druidcaesa/gotool"
- "log"
- "runtime"
- "strconv"
- "time"
- )
- // DEV 开发环境
- const DEV = "dev"
- // PROD 生产环境
- const PROD = "prod"
- const Version = "1.0.9"
- var (
- Cfg *goconfig.ConfigFile
- WechatCfg *WechatConfig
- )
- func init() {
- var err error
- var build string
- if IsDev() {
- build = DEV
- } else {
- build = PROD
- }
- Cfg, err = goconfig.LoadConfigFile("./config/config-" + build + ".ini")
- if err != nil {
- log.Fatal(err)
- }
- return
- }
- type JwtConfig struct {
- TimeOut time.Duration //超时时间
- Issuer string //签证签发人
- Cache string
- }
- type SmsConfig struct {
- AccessKeyID string //签证签发人
- AccessKeySecret string
- }
- // FilePath 文件存储配置获取
- type FilePath struct {
- Path string
- }
- // CaptchaConfig 文件存储配置获取
- type CaptchaConfig struct {
- Type string
- }
- type AuthConfig struct {
- IsOpen string
- }
- // DbCfg Mysql数据库配置
- type DbCfg struct {
- Username string
- Password string
- Database string
- Host string
- Port string
- MaxIdleConnection int
- MaxOpenConnection int
- ShowType string
- }
- // AppServer 应用程序配置
- type AppServer struct {
- Port string //App运行端口
- Lock string //是否开启多终端登录 0开启 1不开启
- DemoEnabled bool //是否是演示模式
- Redis bool //是否开启redis
- }
- // LoggerCfg 日志配置结构体
- type LoggerCfg struct {
- LogPath string
- LogName string
- }
- // RedisCfg redis配置结构体
- type RedisCfg struct {
- RedisHost string //地址
- Port int64 //端口
- RedisPwd string //密码
- RedisDB int64 //数据库
- Timeout int64 //超时时间
- }
- // MongoDb mongo配置结构体
- type MongoDb struct {
- Url string
- Port string
- DB string
- User string
- Password string
- }
- // WechatConfig 微信配置结构体
- type WechatConfig struct {
- MiniProgramAppId string //小程序appId
- MiniProgramSecret string //小程序app secret
- MchID string //微信支付商户号ID
- MchApiV2Key string //微信商户里面设置的API V2密钥
- MchApiV3Key string //微信商户里面设置的API V3密钥
- CertPath string //微信商户里面设置的API V3证书
- KeyPath string //API V3私钥。
- SerialNo string //微信支付V3证书的序列号
- NotifyHost string //微信支付完成后的通知回调地址域名
- NotifyURL string //微信支付完成后的通知回调地址
- NotifyRefundURL string //微信退款完成后的通知回调地址
- }
- type SysCfg struct {
- Version string //版本号
- InstallPath string //安装包路径
- IntegralSn string //积分服务Sn号
- CouponSn string //优惠券服务Sn号
- }
- type OmsApiCfg struct {
- CommonSetting string //总台获取配置接口
- MarketAppId string //总台appId
- ServiceAppId string //服务市场appId
- ServiceAppSecret string //服务市场密钥
- AccountLogin string //登录token接口
- LoginRedirection string //重定向登录
- DeliverDetail string //POST设置服务,GET获取服务详情
- DeliverPostTrack string //获取骑手位置
- DeliverOrderLogs string //配送记录(订单配送详情)
- DeliverOrderStart string //配送发起
- DeliverOrderPrice string //配送价格获取【多平台】
- DeliverOrder string //GET订单详情,POST创建订单
- DeliverOrderCancel string //取消订单
- ServiceList string //服务列表
- ServiceDetail string //服务详情
- ServiceCategories string //服务分类列表
- ServiceMemberLists string //已购服务列表
- UploadConfig string //上传配置
- ServiceBuy string //服务购买
- ServiceUse string //数量类型服务消耗
- ServiceUseCheck string //验证服务useSN
- ServiceLogs string //服务消耗记录
- ServiceInfo string //服务市场信息
- }
- type PrinterCfg struct {
- Appid string //商鹏云打印机用户唯一凭证
- AppSecret string //商鹏云打印机API密钥
- PrinterAdd string //添加打印机
- PrinterInfo string //获取打印机信息
- PrinterUpdate string //修改打印机信息
- PrinterSetting string //修改打印机配置参数
- PrinterDelete string //删除打印机
- PrinterPrint string //打印订单
- PrinterClear string //清空待打印订单
- PrinterOrderStatus string //查询打印订单状态
- PrinterOrderNumber string //查询打印机历史打印订单数
- }
- // GetMysqlCfg 读取mysql配置
- func GetMysqlCfg() (mysql DbCfg) {
- mysql.Username, _ = Cfg.GetValue("mysql", "username")
- mysql.Password, _ = Cfg.GetValue("mysql", "password")
- mysql.Database, _ = Cfg.GetValue("mysql", "database")
- mysql.Host, _ = Cfg.GetValue("mysql", "host")
- mysql.Port, _ = Cfg.GetValue("mysql", "port")
- mysql.ShowType, _ = Cfg.GetValue("mysql", "sqlType")
- value, _ := Cfg.GetValue("mysql", "MaxIdleConnection")
- mysql.MaxIdleConnection, _ = strconv.Atoi(value)
- v, _ := Cfg.GetValue("mysql", "MaxOpenConnection")
- mysql.MaxOpenConnection, _ = strconv.Atoi(v)
- return mysql
- }
- // GetServerCfg 读取server配置
- func GetServerCfg() (server AppServer) {
- server.Port, _ = Cfg.GetValue("app", "server")
- server.Lock, _ = Cfg.GetValue("app", "lock")
- demoEnabled, _ := Cfg.GetValue("app", "demoEnabled")
- redis, _ := Cfg.GetValue("app", "redis")
- server.Redis = redis == "0"
- server.DemoEnabled = demoEnabled == "0"
- return server
- }
- // GetLoggerCfg 获取Logger配置
- func GetLoggerCfg() (logger LoggerCfg) {
- logger.LogPath, _ = Cfg.GetValue("logger", "logPath")
- if IsDev() {
- logger.LogPath = "c:/" + logger.LogPath
- }
- logger.LogName, _ = Cfg.GetValue("logger", "logName")
- return logger
- }
- // GetMongoCfg 获取mongo配置
- func GetMongoCfg() (mongo MongoDb) {
- mongo.Url, _ = Cfg.GetValue("mongodb", "url")
- mongo.Port, _ = Cfg.GetValue("mongodb", "port")
- mongo.DB, _ = Cfg.GetValue("mongodb", "db")
- mongo.User, _ = Cfg.GetValue("mongodb", "user")
- mongo.Password, _ = Cfg.GetValue("mongodb", "password")
- return mongo
- }
- // GetRedisCfg 获取redis配置
- func GetRedisCfg() (r RedisCfg) {
- r.RedisHost, _ = Cfg.GetValue("redis", "host")
- getValue, _ := Cfg.GetValue("redis", "port")
- r.Port, _ = strconv.ParseInt(getValue, 10, 32)
- r.RedisPwd, _ = Cfg.GetValue("redis", "password")
- db, _ := Cfg.GetValue("redis", "db")
- r.RedisDB, _ = strconv.ParseInt(db, 10, 32)
- value, _ := Cfg.GetValue("redis", "timeout")
- r.Timeout, _ = strconv.ParseInt(value, 10, 64)
- return r
- }
- // GetFilePath 获取文件存储位置
- func GetFilePath() (g FilePath) {
- g.Path, _ = Cfg.GetValue("filePath", "path")
- if IsDev() {
- g.Path = "c:/" + g.Path
- }
- return g
- }
- // GetCaptchaConfig 获取文件存储位置
- func GetCaptchaConfig() (g CaptchaConfig) {
- g.Type, _ = Cfg.GetValue("captchaConfig", "type")
- return g
- }
- // GetAuthConfig 开启后端认证
- func GetAuthConfig() (g AuthConfig) {
- g.IsOpen, _ = Cfg.GetValue("auth", "isOpen")
- return g
- }
- func GetJwtConfig() (j JwtConfig) {
- value, _ := Cfg.GetValue("jwt", "timeOut")
- issuer, _ := Cfg.GetValue("jwt", "issuer")
- cache, _ := Cfg.GetValue("jwt", "cache")
- if gotool.StrUtils.HasEmpty(value) {
- value = "60"
- }
- if gotool.StrUtils.HasEmpty(issuer) {
- value = "monkey-cool"
- }
- if gotool.StrUtils.HasEmpty(cache) {
- value = "memory"
- }
- timeOut, _ := strconv.ParseInt(value, 10, 64)
- j.TimeOut = time.Duration(timeOut)
- j.Issuer = issuer
- j.Cache = cache
- return j
- }
- func GetWechatConfig() (g WechatConfig) {
- g.MiniProgramAppId, _ = Cfg.GetValue("wechat", "miniProgramAppId")
- g.MiniProgramSecret, _ = Cfg.GetValue("wechat", "miniProgramSecret")
- g.MchID, _ = Cfg.GetValue("wechat", "mchID")
- g.MchApiV2Key, _ = Cfg.GetValue("wechat", "mchApiV2Key")
- g.MchApiV3Key, _ = Cfg.GetValue("wechat", "mchApiV3Key")
- g.CertPath, _ = Cfg.GetValue("wechat", "certPath")
- g.KeyPath, _ = Cfg.GetValue("wechat", "keyPath")
- if IsDev() {
- g.CertPath = "c:/" + g.CertPath
- g.KeyPath = "c:/" + g.KeyPath
- }
- g.SerialNo, _ = Cfg.GetValue("wechat", "serialNo")
- g.NotifyHost, _ = Cfg.GetValue("wechat", "notifyHost")
- g.NotifyURL, _ = Cfg.GetValue("wechat", "notifyURL")
- g.NotifyRefundURL, _ = Cfg.GetValue("wechat", "notifyRefundURL")
- return g
- }
- func GetOmsApiCfg() (g OmsApiCfg) {
- g.CommonSetting, _ = Cfg.GetValue("oms", "commonSetting")
- g.MarketAppId, _ = Cfg.GetValue("oms", "marketAppId")
- g.ServiceAppId, _ = Cfg.GetValue("oms", "serviceAppId")
- g.ServiceAppSecret, _ = Cfg.GetValue("oms", "serviceAppSecret")
- g.AccountLogin = "/api/account/v1/login"
- g.LoginRedirection = "/api/account/v1/login/redirection"
- g.DeliverDetail = "/api/deliver/detail"
- g.DeliverPostTrack = "/api/deliver/order/post-track"
- g.DeliverOrderLogs = "/api/deliver/order/logs"
- g.DeliverOrderStart = "/api/deliver/order/start"
- g.DeliverOrderPrice = "/api/deliver/order/price"
- g.DeliverOrder = "/api/deliver/order"
- g.DeliverOrderCancel = "/api/deliver/order/cancel"
- g.ServiceList = "/api/service/v1/services"
- g.ServiceDetail = "/api/service/v1/service"
- g.ServiceCategories = "/api/service/v1/categories"
- g.ServiceMemberLists = "/api/service/v1/member/lists"
- g.ServiceBuy = "/api/service/v1/buy"
- g.ServiceUse = "/api/service/v1/service/use"
- g.ServiceUseCheck = "/api/service/v1/service/use/check"
- g.ServiceLogs = "/api/service/v1/logs"
- g.ServiceInfo = "/api/account/v1/info"
- g.UploadConfig = "/api/account/v1/config"
- return g
- }
- func GetSysCfg() (g SysCfg) {
- g.Version = Version
- g.InstallPath = "./look_update.zip"
- g.IntegralSn = "480ff456"
- g.CouponSn = "65af5f28"
- return g
- }
- func GetSmsCfg() (g SmsConfig) {
- g.AccessKeyID, _ = Cfg.GetValue("sms", "accessKeyID")
- g.AccessKeySecret, _ = Cfg.GetValue("sms", "accessKeySecret")
- return g
- }
- func GetPrinterCfg() (g PrinterCfg) {
- g.Appid = "sp63ae90383c07d"
- g.AppSecret = "6064c1365df51dafae0e83544159caf1"
- g.PrinterAdd = "https://open.spyun.net/v1/printer/add"
- g.PrinterInfo = "https://open.spyun.net/v1/printer/info"
- g.PrinterUpdate = "https://open.spyun.net/v1/printer/update"
- g.PrinterSetting = "https://open.spyun.net/v1/printer/setting"
- g.PrinterDelete = "https://open.spyun.net/v1/printer/delete"
- g.PrinterPrint = "https://open.spyun.net/v1/printer/print"
- g.PrinterClear = "https://open.spyun.net/v1/printer/cleansqs"
- g.PrinterOrderStatus = "https://open.spyun.net/v1/printer/order/status"
- g.PrinterOrderNumber = "https://open.spyun.net/v1/printer/order/number"
- return g
- }
- func IsDev() bool {
- /* for _, v := range os.Args {
- if v == "dev" {
- return true
- }
- }
- return false*/
- return runtime.GOOS == "windows"
- //return true
- }
|