func getClient(address string) (openflights.Client, error) { if address != "" { clientConn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { return nil, err } return openflights.NewClient(openflights.NewAPIClient(clientConn)), nil } return openflights.NewDefaultServerClient() }
func do(appEnvObj interface{}) error { appEnv := appEnvObj.(*appEnv) pkglog.SetupLogging(os.Args[0], appEnv.LogEnv) client, err := openflights.NewDefaultServerClient() if err != nil { return err } return protoserver.Serve( appEnv.Port, func(s *grpc.Server) { openflights.RegisterAPIServer(s, openflights.NewAPIServer(client)) }, protoserver.ServeOptions{ HTTPPort: appEnv.HTTPPort, DebugPort: appEnv.DebugPort, HTTPRegisterFunc: openflights.RegisterAPIHandler, Version: openflights.Version, }, ) }
// Do runs the daemon. func Do(options DoOptions) error { client, err := openflights.NewDefaultServerClient() if err != nil { return err } if err := envlion.Setup(); err != nil { return err } return protoserver.GetAndServeWithHTTP( func(grpcServer *grpc.Server) { openflights.RegisterAPIServer(grpcServer, openflights.NewAPIServer(client)) }, openflights.RegisterAPIHandler, protoserver.ServeWithHTTPOptions{ HTTPHandlerModifier: func(httpHandler http.Handler) (http.Handler, error) { if options.GRPCGatewayModifier == nil { return httpHandler, nil } return options.GRPCGatewayModifier(client, httpHandler) }, }, ) }