예제 #1
0
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()
}
예제 #2
0
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,
		},
	)
}
예제 #3
0
// 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)
			},
		},
	)
}