MCPcopy
hub / github.com/fagongzi/manba / main

Function main

cmd/api/api_server.go:39–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37)
38
39func main() {
40 flag.Parse()
41
42 if *version && util.PrintVersion() {
43 os.Exit(0)
44 }
45
46 log.InitLog()
47 runtime.GOMAXPROCS(runtime.NumCPU())
48
49 log.Infof("addr: %s", *addr)
50 log.Infof("addr-store: %s", *addrStore)
51 log.Infof("addr-store-user: %s", *addrStoreUser)
52 log.Infof("addr-store-pwd: %s", *addrStorePwd)
53 log.Infof("namespace: %s", *namespace)
54 log.Infof("discovery: %v", *discovery)
55 log.Infof("service-prefix: %s", *servicePrefix)
56 log.Infof("publish-lease: %d", *publishLease)
57 log.Infof("publish-timeout: %d", *publishTimeout)
58
59 db, err := store.GetStoreFrom(*addrStore, fmt.Sprintf("/%s", *namespace), *addrStoreUser, *addrStorePwd)
60 if err != nil {
61 log.Fatalf("init store failed for %s, errors:\n%+v",
62 *addrStore,
63 err)
64 }
65
66 service.Init(db)
67
68 var opts []grpcx.ServerOption
69 if *discovery {
70 opts = append(opts, grpcx.WithEtcdPublisher(db.Raw().(*clientv3.Client), *servicePrefix, *publishLease, time.Second*time.Duration(*publishTimeout)))
71 }
72
73 if *addrHTTP != "" {
74 opts = append(opts, grpcx.WithHTTPServer(*addrHTTP, func(server *echo.Echo) {
75 service.InitHTTPRouter(server, *ui, *uiPrefix)
76 }))
77 }
78
79 s := grpcx.NewGRPCServer(*addr, func(svr *grpc.Server) []grpcx.Service {
80 var services []grpcx.Service
81 rpcpb.RegisterMetaServiceServer(svr, service.MetaService)
82 services = append(services, grpcx.NewService(rpcpb.ServiceMeta, nil))
83 return services
84 }, opts...)
85
86 log.Infof("api server listen at %s", *addr)
87 go s.Start()
88
89 waitStop(s)
90}
91
92func waitStop(s *grpcx.GRPCServer) {
93 sc := make(chan os.Signal, 1)

Callers

nothing calls this directly

Calls 8

PrintVersionFunction · 0.92
GetStoreFromFunction · 0.92
InitFunction · 0.92
InitHTTPRouterFunction · 0.92
StartMethod · 0.80
waitStopFunction · 0.70
RawMethod · 0.65

Tested by

no test coverage detected