Documentation ¶
Index ¶
- type MicroService
- type MicroServiceOption
- func WithAggresiveGC() MicroServiceOption
- func WithContext(ctx context.Context) MicroServiceOption
- func WithGRPC(preprocess func(grpcServer *grpc.Server)) MicroServiceOption
- func WithGRPCStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) MicroServiceOption
- func WithGRPCUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) MicroServiceOption
- func WithHTTPCORS() MicroServiceOption
- func WithHttpHandler(pattern string, handler http.Handler) MicroServiceOption
- func WithNamedWorker(name string, worker func(ctx context.Context) error) MicroServiceOption
- func WithPprof() MicroServiceOption
- func WithPrometheus() MicroServiceOption
- func WithPrometheusWithPrefix(prefix string) MicroServiceOption
- func WithRecover() MicroServiceOption
- func WithRegisterConsul() MicroServiceOption
- func WithServerOptions(options ...grpc.ServerOption) MicroServiceOption
- func WithWorker(worker func(ctx context.Context) error) MicroServiceOption
- type ServiceInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MicroService ¶
type MicroService struct {
// contains filtered or unexported fields
}
MicroService is a All-in-one container for hosting grpc and/or http server, along with multiple predefined utils.
func NewMicroService ¶
func NewMicroService(opts ...MicroServiceOption) *MicroService
NewMicroService return an object to setup micro service in cloud.
func (*MicroService) GetSelfGRPCConnection ¶ added in v1.0.2
func (ms *MicroService) GetSelfGRPCConnection(ctx context.Context) (*grpc.ClientConn, error)
func (*MicroService) ListenAndServe ¶
func (ms *MicroService) ListenAndServe(port int) error
ListenAndServe start service server by given `port`, If `port==0`, a random available port will be used.
type MicroServiceOption ¶
type MicroServiceOption func(ms *MicroService)
MicroServiceOption offer config tuning for micro service.
func WithAggresiveGC ¶
func WithAggresiveGC() MicroServiceOption
WithAggresiveGC invokes Garbage Collecting periodically, to reduce small chunk of files memory footprint reserved by Go.
func WithContext ¶
func WithContext(ctx context.Context) MicroServiceOption
WithContext sets the context for whole microservice. When ctx get done, the microservice will be terminated.
func WithGRPC ¶
func WithGRPC(preprocess func(grpcServer *grpc.Server)) MicroServiceOption
WithGRPC binds a grpc server. Example usage:
```service.WithhGRPC(func(gs *grpc.Server) { pb.RegisterServiceServer(gs, NewServiceServer()) }```
func WithGRPCStreamInterceptors ¶
func WithGRPCStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) MicroServiceOption
WithGRPCStreamInterceptors chained given interceptors with MicroService default StreamServerInterceptor using grpc_middleware
func WithGRPCUnaryInterceptors ¶
func WithGRPCUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) MicroServiceOption
WithGRPCUnaryInterceptors chained given interceptors with MicroService default UnaryServerInterceptors using grpc_middleware
func WithHTTPCORS ¶
func WithHTTPCORS() MicroServiceOption
WithHTTPCORS enables cors for http endpoint. Should not enable in production.
func WithHttpHandler ¶
func WithHttpHandler(pattern string, handler http.Handler) MicroServiceOption
WithHttpHandler binds a http server implementing http.Handler This handler has better pattern definition. Two kinds of pattern: 1. `{pattern}/`: any path has prefix of pattern, it should be partial of the path. 2. `{pattern}`: no backslash. An fixed endpoint, which should be the whole path.
func WithNamedWorker ¶
func WithNamedWorker(name string, worker func(ctx context.Context) error) MicroServiceOption
WithNamedWorker adds dependency worker with this service. If the worker returns, the microservice will be terminated.
func WithPprof ¶
func WithPprof() MicroServiceOption
WithPprof register the golang built-in profiling interface to `/debug` http path.
func WithPrometheus ¶
func WithPrometheus() MicroServiceOption
WithPrometheus registers the service to monitor infrastructure.
func WithPrometheusWithPrefix ¶
func WithPrometheusWithPrefix(prefix string) MicroServiceOption
WithPrometheusWithHandler registers the service to monitor infrastructure with customized handler.
func WithRegisterConsul ¶ added in v1.0.2
func WithRegisterConsul() MicroServiceOption
WithRegisterConsul binds the service to the service name defined in shared.Servicename.
func WithServerOptions ¶
func WithServerOptions(options ...grpc.ServerOption) MicroServiceOption
WithServerOptions sets the GRPC server options. Common used to set grpc message size, like `service.WithServerOptions(grpc.MaxRecvMsgSize(1024*1024*16))`
func WithWorker ¶
func WithWorker(worker func(ctx context.Context) error) MicroServiceOption
WithWorker adds dependency worker with this service. If the worker returns, the microservice will be terminated.
type ServiceInfo ¶
type ServiceInfo struct { BuildInfo *debug.BuildInfo `json:"build_info"` FrmeworkVersion string `json:"framework_version"` Datacenter string `json:"datacenter"` ServiceName string `json:"service_name"` ServiceTag string `json:"service_tag"` RemoteWatchPath string `json:"remote_watch_path"` Workers []string `json:"workers"` Debug bool `json:"debug"` Uptime time.Duration `json:"uptime"` UptimePretty string `json:"uptime_pretty"` StartTime time.Time `json:"start_time"` Dependencies []string `json:"dependencies"` Host interface{} `json:"host"` Self interface{} `json:"self"` }