45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
||
|
||
import (
|
||
"context"
|
||
"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,
|
||
// })
|
||
|
||
//gin初始化,基于docker部署,不再需要调整默认值(80)
|
||
|
||
consul.Init(&consul.Config{
|
||
Address: "192.168.0.214:8500",
|
||
})
|
||
|
||
gin.Service(nil)
|
||
|
||
if err := consul.RegisterAPI("demo1", "192.168.0.214", 8080, ""); 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")
|
||
os.Exit(0)
|
||
}
|