diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..85266a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +release: + go mod tidy + GOOS=linux go build -o demo1 . + scp demo1 ubuntu@192.168.0.214:~/ \ No newline at end of file diff --git a/__debug_bin b/__debug_bin new file mode 100755 index 0000000..535f9b1 Binary files /dev/null and b/__debug_bin differ diff --git a/gin/router.go b/gin/router.go index 90054bc..8ce2b1d 100644 --- a/gin/router.go +++ b/gin/router.go @@ -26,7 +26,7 @@ func routerSetup(router *gin.Engine, rootpath *string) { ug.GET(`/detail`) ug.POST(`/update`) } - hell := router.Group("token") + hell := router.Group("/token") { hell.GET("verify", handler.TokenVerify) diff --git a/go.mod b/go.mod index 1f1f1ae..254b45e 100644 --- a/go.mod +++ b/go.mod @@ -11,10 +11,15 @@ require ( ) require ( - github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect + github.com/google/btree v1.0.0 // indirect + github.com/google/go-cmp v0.5.9 // indirect +) + +require ( + github.com/armon/go-metrics v0.4.0 // indirect github.com/bytedance/sonic v1.8.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/fatih/color v1.9.0 // indirect + github.com/fatih/color v1.13.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect @@ -22,9 +27,9 @@ require ( github.com/goccy/go-json v0.10.0 // indirect github.com/gomodule/redigo v1.8.9 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/hashicorp/go-cleanhttp v0.5.1 // indirect - github.com/hashicorp/go-hclog v0.12.0 // indirect - github.com/hashicorp/go-immutable-radix v1.0.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-hclog v1.2.0 // indirect + github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/serf v0.10.1 // indirect @@ -33,10 +38,10 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-colorable v0.1.6 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/mitchellh/mapstructure v1.4.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect diff --git a/main.go b/main.go index e6550a5..a6014eb 100644 --- a/main.go +++ b/main.go @@ -2,43 +2,42 @@ package main import ( "context" + "flag" "fmt" "os" "os/signal" "time" - "myschools.me/campus/campus-core/exceptionless" "myschools.me/campus/demo-1/consul" "myschools.me/campus/demo-1/gin" ) func main() { - // 日志初始化 - // exceptionless.Init(&exceptionless.Config{ - // ApiKey: os.Getenv("EXCEPTIONLESS_KEY"), - // ServerURL: os.Getenv("EXCEPTIONLESS_URL"), - // UpdateSettingsWhenIdleInterval: 0, - // }) + appname := flag.String("appname", "demo1", "app name for current") + tags := flag.String("tags", `PathPrefix("/demo")`, "consul tags") + port := flag.Int("port", 8080, "port for gin") + addr := flag.String("addr", "localhost", "ip address for gin") + flag.Parse() - //gin初始化,基于docker部署,不再需要调整默认值(80) + consul.Init(nil) - consul.Init(&consul.Config{ - Address: "192.168.0.214:8500", + gin.Service(&gin.Config{ + RootPath: *appname, + Addr: *addr, + Port: *port, }) - gin.Service(nil) - - if err := consul.RegisterAPI("demo1", "192.168.0.214", 8080, ""); err != nil { + traefikTag := fmt.Sprintf(`traefik.http.routers.%s.rule=%s`, *appname, *tags) + if err := consul.RegisterAPI(*appname, *addr, *port, traefikTag); err != nil { fmt.Println("注册失败", err.Error()) } - // exceptionless.SubmitLog(fmt.Sprintf("campus-srv[%s:%d%s] service is running...", conf.Addr, conf.Port, conf.RootPath), "info") // 服务停止相应 c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) <-c _, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() - exceptionless.SubmitLog("campus-srv service shutting down", "info") + fmt.Println("campus-demo1 service shutting down") os.Exit(0) } diff --git a/service/README.md b/service/README.md new file mode 100644 index 0000000..ba13e38 --- /dev/null +++ b/service/README.md @@ -0,0 +1,3 @@ +# campus-demo-2 + +微服务测试demo \ No newline at end of file