Version: v1.2.6 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2022 License: Apache-2.0 Imports: 41 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Service

type Service struct {
	// service properties
	AppName          string
	ConfigFileName   string
	CustomConfigPath string

	// web server config
	WebServerConfig *WebServerConfig

	// register one or more service handlers
	// example: type AnswerServiceImpl struct {
	//				testpb.UnimplementedAnswerServiceServer
	//			}
	//			RegisterServiceHandlers: func(grpcServer *grpc.Server) {
	//				testpb.RegisterAnswerServiceServer(grpcServer, &AnswerServiceImpl{})
	//			},
	RegisterServiceHandlers func(grpcServer *grpc.Server)

	// setup optional health check handlers
	DefaultHealthCheckHandler  func(ctx context.Context) grpc_health_v1.HealthCheckResponse_ServingStatus
	ServiceHealthCheckHandlers map[string]func(ctx context.Context) grpc_health_v1.HealthCheckResponse_ServingStatus

	// setup optional rate limit server interceptor
	RateLimit ratelimiter.RateLimiterIFace

	// one or more unary server interceptors for handling wrapping actions
	UnaryServerInterceptors []grpc.UnaryServerInterceptor

	// one or more stream server interceptors for handling wrapping actions
	StreamServerInterceptors []grpc.StreamServerInterceptor

	// typically wrapper action to handle monitoring
	StatsHandler stats.Handler

	// handler for unknown requests rather than sending back an error
	UnknownStreamHandler grpc.StreamHandler

	// handler to invoke before gRPC server is to start
	BeforeServerStart func(svc *Service)

	// handler to invoke after gRPC server started
	AfterServerStart func(svc *Service)

	// handler to invoke before gRPC server is to shutdown
	BeforeServerShutdown func(svc *Service)

	// handler to invoke after gRPC server has shutdown
	AfterServerShutdown func(svc *Service)
	// contains filtered or unexported fields

Service represents a gRPC server's service definition and entry point

AppName = (required) name of this service ConfigFileName = (required) config file name without .yaml extension CustomConfigPath = (optional) if not specified, . is assumed RegisterServiceHandlers = (required) func to register grpc service handlers

When calling RPC services, To pass in parent xray segment id and trace id, set the metadata keys with:

x-amzn-seg-id = parent xray segment id, assign value to this key via metadata.MD
x-amzn-tr-id = parent xray trace id, assign value to this key via metadata.MD

How to set metadata at client side?

ctx := context.Background()
md := metadata.Pairs("x-amzn-seg-id", "abc", "x-amzn-tr-id", "def")
ctx = metadata.NewOutgoingContext(ctx, md)

func NewService

func NewService(appName string, configFileName string, customConfigPath string, registerServiceHandlers func(grpcServer *grpc.Server)) *Service

create service

func (*Service) CurrentlyServing

func (s *Service) CurrentlyServing() bool

CurrentlyServing indicates if this service health status indicates currently serving mode or not

func (*Service) GracefulStop

func (s *Service) GracefulStop()

GracefulStop allows existing actions be completed before shutting down gRPC server

func (*Service) ImmediateStop

func (s *Service) ImmediateStop()

ImmediateStop will forcefully shutdown gRPC server regardless of pending actions being processed

func (*Service) LocalAddress

func (s *Service) LocalAddress() string

LocalAddress returns the service server's address and port

func (*Service) Serve

func (s *Service) Serve() error

Serve will setup grpc service and start serving

type WebServerConfig added in v1.0.6

type WebServerConfig struct {
	AppName          string
	ConfigFileName   string
	CustomConfigPath string

	// define web server router info
	WebServerRoutes map[string]*ginw.RouteDefinition

	// getter only
	WebServerLocalAddress string

	// clean up func
	CleanUp func()

note: WebServerLocalAddress = read only getter

note: WebServerRoutes = map[string]*ginw.RouteDefinition{
		"base": {
			Routes: []*ginw.Route{
					Method: ginhttpmethod.GET,
					RelativePath: "/",
					Handler: func(c *gin.Context, bindingInputPtr interface{}) {
						c.String(200, "Connector Service Http Host Up")

func (*WebServerConfig) GetWebServerLocalAddress added in v1.0.7

func (w *WebServerConfig) GetWebServerLocalAddress() string

GetWebServerLocalAddress returns FQDN url to the local web server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL