service

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

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) 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.

func (*MicroService) Serve

func (ms *MicroService) Serve(listener net.Listener) error

Serve starts the micro service server using given listener.

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(srv *grpc.Server)) MicroServiceOption

WithGRPC binds a grpc server. Example usage:

```service.WithhGRPC(func(gs *grpc.Server) {
   pb.RegisterServiceServer(gs, NewServiceServer())
}```

func WithGRPCConnCallback

func WithGRPCConnCallback(cb func(conn *grpc.ClientConn)) MicroServiceOption

WithGRPCConnCallback is invoked after GRPC server starts serving, and a self-connect GRPC connection will be dialed and be returned in the callback.

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 WithGRPCValidator

func WithGRPCValidator() MicroServiceOption

WithGRPCValidator enable validator for message in GRPC if any one was defined.

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 WithRecover

func WithRecover() MicroServiceOption

WithRecover

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.

func WithoutGRPCReflection

func WithoutGRPCReflection() MicroServiceOption

func WithoutHTTPClientMonitor

func WithoutHTTPClientMonitor() MicroServiceOption

func WithoutHTTPLogTail

func WithoutHTTPLogTail() MicroServiceOption

func WithoutServiceInfo

func WithoutServiceInfo() MicroServiceOption

type ServiceInfo

type ServiceInfo struct {
	BuildGitCommitId string        `json:"build_git_commit_id"`
	BuildTime        string        `json:"build_time"`
	FrmeworkVersion  string        `json:"framework_version"`
	Datacenter       string        `json:"datacenter"`
	ServiceNames     []string      `json:"service_names"`
	RemoteWatchPath  string        `json:"remote_watch_path"`
	Owner            string        `json:"owner"`
	Workers          []string      `json:"workers"`
	UniqueWorkers    []string      `json:"unique_workers"`
	Tags             []string      `json:"tags"`
	Debug            bool          `json:"debug"`
	Uptime           time.Duration `json:"uptime"`
	UptimePretty     string        `json:"uptime_pretty"`
	StartTime        time.Time     `json:"start_time"`
	APITestEnabled   bool          `json:"api_test_enabled"`
	Dependencies     []string      `json:"dependencies"`
	Host             interface{}   `json:"host"`
	Self             interface{}   `json:"self"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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