代码拉取完成,页面将自动刷新
package main
import (
"net"
"net/http"
"os"
pb "snowflake/proto"
cli "gopkg.in/urfave/cli.v2"
log "github.com/Sirupsen/logrus"
"google.golang.org/grpc"
)
func main() {
go func() {
log.Info(http.ListenAndServe("0.0.0.0:6060", nil))
}()
app := &cli.App{
Name: "snowflake",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "listen",
Value: ":10000",
Usage: "listening address:port",
},
&cli.StringSliceFlag{
Name: "etcd-hosts",
Value: cli.NewStringSlice("http://127.0.0.1:2379"),
Usage: "etcd hosts",
},
&cli.IntFlag{
Name: "machine-id",
Value: 0,
Usage: "snowflake machine id, 0-1023",
},
&cli.StringFlag{
Name: "pk-root",
Value: "/seqs",
Usage: "path for auto increment primary keys",
},
&cli.StringFlag{
Name: "uuid-key",
Value: "/seqs/snowflake-uuid",
Usage: "uuid main key",
},
},
Action: func(c *cli.Context) error {
log.Println("listen:", c.String("listen"))
log.Println("etcd-hosts:", c.StringSlice("etcd-hosts"))
log.Println("machine-id:", c.Int("machine-id"))
log.Println("pk-root:", c.String("pk-root"))
log.Println("uuid-key:", c.String("uuid-key"))
// 监听
lis, err := net.Listen("tcp", c.String("listen"))
if err != nil {
log.Fatalln(err)
}
log.Info("listening on ", lis.Addr())
// 注册服务
s := grpc.NewServer()
ins := &server{}
ins.init(c)
pb.RegisterSnowflakeServiceServer(s, ins)
// 开始服务
return s.Serve(lis)
},
}
app.Run(os.Args)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。