1 Star 0 Fork 6

lianchangqiong/IdCreator

forked from 0-hun/IdCreator 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
tianxiong 提交于 2021-03-17 15:46 . core.NewSnowFlake
package main
import (
"context"
"flag"
"gitee.com/man0sions/IdCreator/core"
"gitee.com/man0sions/IdCreator/service/rpc"
"gitee.com/man0sions/IdCreator/service/thttp"
"log"
"os"
"os/signal"
"syscall"
)
var (
err error
conf = flag.String("conf", "./config/main.yaml", "conf file")
nodeId = flag.Int64("nodeId", 20, "nodeId")
)
func init() {
log.SetFlags(log.Lshortfile)
}
func start(ctx context.Context) {
if err = core.NewLogger(core.GConfig.Log); err != nil {
log.Panicln(err)
}
if _, err = core.NewSnowFlake(*nodeId); err != nil {
log.Panicln(err)
}
engine := thttp.NewHttpServer(core.GConfig.Viper, thttp.InitRouter)
go rpc.NewRpc(engine, core.GConfig.Viper, "Id_Creator")
}
func main() {
flag.Parse()
ctx, cancel := context.WithCancel(context.TODO())
if err = core.InitConfig(*conf); err != nil {
log.Panicln(err)
}
start(ctx)
exitChan := make(chan os.Signal)
signal.Notify(exitChan, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGSTOP, syscall.SIGTERM)
for {
select {
case <-exitChan:
log.Println("bye ...")
cancel()
thttp.StopHttpServer()
os.Exit(0)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lcq_chang/IdCreator.git
[email protected]:lcq_chang/IdCreator.git
lcq_chang
IdCreator
IdCreator
master

搜索帮助