This commit is contained in:
tcq 2023-04-26 17:13:47 +08:00
parent 39b2ef4c89
commit f1c7f862c6
6 changed files with 34 additions and 23 deletions

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
release:
go mod tidy
GOOS=linux go build -o demo1 .
scp demo1 ubuntu@192.168.0.214:~/

BIN
__debug_bin Executable file

Binary file not shown.

View File

@ -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)

19
go.mod
View File

@ -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

29
main.go
View File

@ -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)
}

3
service/README.md Normal file
View File

@ -0,0 +1,3 @@
# campus-demo-2
微服务测试demo