Quellcode durchsuchen

系统环境相关

kphcdr vor 1 Jahr
Ursprung
Commit
efc8a4babf
5 geänderte Dateien mit 15 neuen und 6 gelöschten Zeilen
  1. 3 0
      cmd/base_command.go
  2. 4 5
      cmd/command.go
  3. 1 1
      common/config.go
  4. 5 0
      common/const.go
  5. 2 0
      main.go

+ 3 - 0
cmd/base_command.go

@@ -29,6 +29,9 @@ func Execute() {
 	cobra.CheckErr(RootCmd.Execute())
 }
 
+func init() {
+	RootCmd.PersistentFlags().StringVarP(&common.Env, "env", "e", "local", "系统环境,支持local dev")
+}
 func startHttp(r *gin.Engine, port string) {
 
 	server := http.Server{

+ 4 - 5
cmd/command.go

@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"fmt"
 	"github.com/spf13/cobra"
 	"ppgo/common"
 )
@@ -17,10 +18,8 @@ func init() {
 }
 
 func RunCmd(cmd *cobra.Command, args []string) {
-	log := common.GetLog()
-	log.SetPrefix("[cmd]")
-	log.Println("haha")
-	log.SetPrefix("[cmd2]")
-	log.Println("haha2")
+	c := common.GetConfig()
+
+	fmt.Printf("%+v", c)
 
 }

+ 1 - 1
common/config.go

@@ -52,7 +52,7 @@ func InitConfig() {
 		} `json:"data"`
 	}
 	rConfig := &remoteConfig{}
-	resp, err := http.PostForm("http://kconf.kphcdr.com/api/config/all?app_key=kphcdr&env=qa", url.Values{})
+	resp, err := http.PostForm(fmt.Sprintf("http://kconf.kphcdr.com/api/config/all?app_key=%s&env=%s", APP_KEY, Env), url.Values{})
 
 	if err != nil {
 		panic(fmt.Sprintf("拉取配置失败:%s", err))

+ 5 - 0
common/const.go

@@ -0,0 +1,5 @@
+package common
+
+var Env string
+
+const APP_KEY = "kphcdr"

+ 2 - 0
main.go

@@ -4,6 +4,8 @@ import (
 	"ppgo/cmd"
 )
 
+const APP_KEY = "kphcdr"
+
 func main() {
 	Ready()
 }