From f0786e779666d67a50cd57d82cfe1e278b47d397 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 04 七月 2024 11:54:11 +0800 Subject: [PATCH] fix --- conf/config.go | 94 ++++++++++++++++++++++++++++++----------------- 1 files changed, 60 insertions(+), 34 deletions(-) diff --git a/conf/config.go b/conf/config.go index 06955ee..da9d1d8 100644 --- a/conf/config.go +++ b/conf/config.go @@ -3,6 +3,7 @@ import ( "log" "os" + "wms/constvar" "wms/pkg/logx" "wms/pkg/mysqlx" @@ -23,35 +24,47 @@ type ( webConf struct { - Host string // 鏈満ip鍦板潃 - Port string // 绔彛鍙� - APPort string // 鏈満浣滀负鐨凣rpc鏈嶅姟绔殑绔彛鍙� - AlHost string // 绠楁硶鏈嶅姟ip鍦板潃 - AlPort string // 绠楁硶鏈嶅姟绔彛鍙� - NodeId string // 涓昏处鎴风敤鎴峰悕 - OssType string // 瀵硅薄瀛樺偍绫诲瀷 - JWTSecret string - } - - nsqConf struct { - NsqdAddr string - NsqlookupdAddr string + Host string // 鏈満ip鍦板潃 + Port string // 绔彛鍙� + NodeId string // 涓昏处鎴风敤鎴峰悕 + OssType string // 瀵硅薄瀛樺偍绫诲瀷 + JWTSecret string + FileServer string //鏂囦欢鏈嶅姟鍣ㄥ湴鍧� + ServerId string //鏈嶅姟ID + Env constvar.Env + GrpcPort string //grpc绔彛鍙� + CompanyName string //鍏徃鍚� } localConf struct { StorePath string // 鏈湴鏂囦欢瀛樺偍璺緞 } + + grpcServerConf struct { + AdminAddr string //admin鏈嶅姟grpc鍦板潃 + ApsAddr string //aps鏈嶅姟grpc鍦板潃 + CrmAddr string //crm鏈嶅姟grpc鍦板潃 + SrmAddr string //srm鏈嶅姟grpc鍦板潃 + } + + fileTemplateConf struct { + InputSelfmadeAddr string //鍏ュ簱鑷埗鍗曟ā鐗堝湴鍧� + } + + dingTalkConf struct { + AlarmKey string + AlarmUrl string + } ) var ( - WebConf = &webConf{} - LogConf = &logx.Conf{} - DbConf = &mysqlx.Conf{} - NsqConf = &nsqConf{} - LocalConf = &localConf{} - NodeId string - GrpcPort string - Viper *viper.Viper + WebConf = &webConf{} + LogConf = &logx.Conf{} + DbConf = &mysqlx.Conf{} + LocalConf = &localConf{} + Viper *viper.Viper + GrpcServerConf = &grpcServerConf{} + DingTalkConf = &dingTalkConf{} ) func Init() error { @@ -66,25 +79,37 @@ } read2Conf(Viper) - GrpcPort = os.Getenv("GRPC_PORT") // 鍙粰grpc绠楁硶鏈嶅姟浣跨敤锛屾湰鏈嶅姟涓嶇敤 nodeId := os.Getenv("NODE_ID") // 涓昏处鎴风敤鎴峰悕 host := os.Getenv("HOST") // 鏈満IP鍦板潃 - algHost := os.Getenv("AL_HOST") // 绠楁硶鏈嶅姟鐨処P鍦板潃 - nsqdAddr := os.Getenv("NSQD_ADDR") - if len(GrpcPort) == 0 { // 濡傛灉gprcPort涓虹┖锛岄偅涔堢敤閰嶇疆鐨凙PPort - GrpcPort = WebConf.APPort + GrpcPort := os.Getenv("WMS_GRPC") // 鍙澶栨彁渚沢rpc鏈嶅姟锛屾湰鏈嶅姟涓嶇敤 + adminAddr := os.Getenv("ADMIN_GRPC") + apsAddr := os.Getenv("APS_GRPC") + crmAddr := os.Getenv("CRM_GRPC") + srmAddr := os.Getenv("SRM_GRPC") + companyName := os.Getenv("COMPANY_NAME") + if len(GrpcPort) > 0 { + WebConf.GrpcPort = GrpcPort } if len(nodeId) > 0 { WebConf.NodeId = nodeId } - if len(algHost) > 0 { - WebConf.AlHost = algHost - } if len(host) > 0 { WebConf.Host = host } - if len(nsqdAddr) > 0 { - NsqConf.NsqdAddr = nsqdAddr + if len(adminAddr) > 0 { + GrpcServerConf.AdminAddr = adminAddr + } + if len(apsAddr) > 0 { + GrpcServerConf.ApsAddr = apsAddr + } + if len(crmAddr) > 0 { + GrpcServerConf.CrmAddr = crmAddr + } + if len(srmAddr) > 0 { + GrpcServerConf.SrmAddr = srmAddr + } + if len(companyName) > 0 { + WebConf.CompanyName = companyName } DBHost := os.Getenv("DB_HOST") @@ -107,8 +132,9 @@ _ = v.UnmarshalKey("web", WebConf) _ = v.UnmarshalKey("log", LogConf) _ = v.UnmarshalKey("db", DbConf) - _ = v.UnmarshalKey("nsq", NsqConf) _ = v.UnmarshalKey("local", LocalConf) + _ = v.UnmarshalKey("grpcServer", GrpcServerConf) + _ = v.UnmarshalKey("dingTalk", DingTalkConf) showConfig() } @@ -117,8 +143,8 @@ log.Printf(" WebConf: %+v", WebConf) log.Printf(" LogConf: %+v", LogConf) log.Printf(" DbConf: %+v", DbConf) - log.Printf(" NsqConf: %+v", NsqConf) - log.Printf(" GrpcPort: %+v", GrpcPort) log.Printf(" LocalConf: %+v", LocalConf) + log.Printf(" GrpcServerConf: %+v", GrpcServerConf) + log.Printf(" DingTalkConf: %+v", DingTalkConf) log.Println("......................................................") } -- Gitblit v1.8.0