Documentation ¶
Index ¶
- func AddServerGracefulStop(server GoMsServerGracefulStopableInterface)
- func Call[T any](ctx context.Context, cm *GrpcClientManager, serviceName, methodName string, ...) (T, error)
- func CatchStopSignals() (done chan bool)
- func GenerateRandomString(length int) (string, error)
- func RegisterServiceMap[T GoMsServiceInterface](constructor func(*Context, string, ServiceConfig) T) func(*Context, string, ServiceConfig) T
- func Trace(ctx context.Context, name string, action string) (context.Context, trace.Span)
- type Application
- type BaseMiddleware
- type Config
- type Context
- type Exporter
- type ExporterConfig
- type GoMsGrpcServer
- func (o *GoMsGrpcServer) AddService(service GoMsServiceInterface)
- func (o *GoMsGrpcServer) GracefulStop() error
- func (o *GoMsGrpcServer) InitServer()
- func (o *GoMsGrpcServer) Listen() (err error)
- func (o *GoMsGrpcServer) Register(service GoMsServiceInterface)
- func (o *GoMsGrpcServer) SetExporter(exporter *Exporter)
- func (o *GoMsGrpcServer) Start() error
- type GoMsHandlerInterface
- type GoMsHttpServer
- func (o *GoMsHttpServer) AddService(service GoMsServiceInterface)
- func (o *GoMsHttpServer) GracefulStop() error
- func (o *GoMsHttpServer) Handle(path string, mux *runtime.ServeMux)
- func (o *GoMsHttpServer) Register(service GoMsServiceInterface) error
- func (o *GoMsHttpServer) SetExporter(exporter *Exporter)
- func (o *GoMsHttpServer) Start() error
- type GoMsMetricsInterface
- type GoMsMiddlewareFunc
- type GoMsServerGracefulStopableInterface
- type GoMsServerState
- type GoMsServiceFunc
- type GoMsServiceInterface
- type GoMsStreamMiddlewareFunc
- type GrpcClientConfiguration
- type GrpcClientManager
- func (o *GrpcClientManager) AddClient(name string, client any)
- func (o *GrpcClientManager) AddServer(name string, host string, port int, timeout time.Duration)
- func (o *GrpcClientManager) GetClient(name string) (any, error)
- func (o *GrpcClientManager) GetConnection(name string) (*grpc.ClientConn, error)
- func (o *GrpcClientManager) InitConnections() error
- type HttpServerConfig
- type JaegerConfig
- type Jeager
- type MetadataReaderWriter
- type Middleware
- type ResponseWriterHandler
- type ServerConfig
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddServerGracefulStop ¶
func AddServerGracefulStop(server GoMsServerGracefulStopableInterface)
func GenerateRandomString ¶
func RegisterServiceMap ¶
func RegisterServiceMap[T GoMsServiceInterface](constructor func(*Context, string, ServiceConfig) T) func(*Context, string, ServiceConfig) T
Types ¶
type Application ¶
type Application struct { Services map[string]GoMsServiceInterface // contains filtered or unexported fields }
func NewApplication ¶
func NewApplication(config *Config, services map[string]GoMsServiceFunc, middlewares map[string]Middleware) *Application
func NewApplicationFromConfigFile ¶
func NewApplicationFromConfigFile(configPath string, services map[string]GoMsServiceFunc, middlewares map[string]Middleware) *Application
func (*Application) InitService ¶
func (o *Application) InitService(name string, config ServiceConfig) GoMsServiceInterface
func (*Application) RegisterService ¶
func (o *Application) RegisterService(name string, constructor GoMsServiceFunc)
func (*Application) RegisterServices ¶
func (o *Application) RegisterServices(services map[string]GoMsServiceFunc)
func (*Application) Start ¶
func (o *Application) Start()
type BaseMiddleware ¶
type BaseMiddleware struct {
Middleware
}
func (*BaseMiddleware) Stream ¶
func (m *BaseMiddleware) Stream() grpc.StreamServerInterceptor
func (*BaseMiddleware) Unary ¶
func (m *BaseMiddleware) Unary() grpc.UnaryServerInterceptor
type Config ¶
type Config struct { Name string `yaml:"name"` Grpc *ServerConfig `yaml:"grpc,omitempty"` Http *HttpServerConfig `yaml:"http,omitempty"` Exporter ExporterConfig `yaml:"exporter,omitempty"` Jaeger JaegerConfig `yaml:"jaeger,omitempty"` Services map[string]ServiceConfig `yaml:"services"` Middleware []string `yaml:"middlewares,omitempty"` }
type Context ¶
func NewContext ¶
func NewContext(name string, jconfig JaegerConfig) *Context
type Exporter ¶
type Exporter struct { Ctx context.Context Server *http.Server Mux *http.ServeMux // contains filtered or unexported fields }
Definition of Exporter struct for expose scrapped metrics
func NewExporter ¶
Initialize a exporter strucs
func (*Exporter) GracefulStop ¶
func (*Exporter) HandleHttpHandler ¶
Http Gateway middleware for handle metrics on all requests services
func (*Exporter) IncrRequests ¶
Increment Gauge request by code, method and path
func (*Exporter) WatchedMetrics ¶
func (o *Exporter) WatchedMetrics()
Not used yet Watch metrics in the interval time
type ExporterConfig ¶
type GoMsGrpcServer ¶
type GoMsGrpcServer struct { Ctx *Context Host string Port int Server *grpc.Server State GoMsServerState Opts []grpc.DialOption Exporter *Exporter Middlewares map[string]Middleware MiddlewaresConf map[string]map[string][]string // contains filtered or unexported fields }
Define the GRPC Server Struct
func NewGoMsGrpcServer ¶
func NewGoMsGrpcServer(appCtx *Context, config *ServerConfig, opts []grpc.DialOption, middlewares map[string]Middleware) *GoMsGrpcServer
Create a grpc server
func (*GoMsGrpcServer) AddService ¶
func (o *GoMsGrpcServer) AddService(service GoMsServiceInterface)
Add service to the local service array, need for register later
func (*GoMsGrpcServer) GracefulStop ¶
func (o *GoMsGrpcServer) GracefulStop() error
Graceful stop, when SIG_TERM is send
func (*GoMsGrpcServer) InitServer ¶
func (o *GoMsGrpcServer) InitServer()
func (*GoMsGrpcServer) Listen ¶
func (o *GoMsGrpcServer) Listen() (err error)
Start listen tcp socket for handle grpc service
func (*GoMsGrpcServer) Register ¶
func (o *GoMsGrpcServer) Register(service GoMsServiceInterface)
Register service on the grpc server
func (*GoMsGrpcServer) SetExporter ¶
func (o *GoMsGrpcServer) SetExporter(exporter *Exporter)
Set the exporter
func (*GoMsGrpcServer) Start ¶
func (o *GoMsGrpcServer) Start() error
Start a grpc server ready for handle connexion
type GoMsHandlerInterface ¶
type GoMsHandlerInterface interface { RegisterHttp(*GoMsHttpServer, GoMsServiceInterface) error RegisterGrpc(*GoMsGrpcServer, GoMsServiceInterface) }
type GoMsHttpServer ¶
type GoMsHttpServer struct { Ctx *Context Grpc *GoMsGrpcServer Host string Port int Server *http.Server State GoMsServerState Mux *runtime.ServeMux Exporter *Exporter // contains filtered or unexported fields }
Definition of GoMsHttpServer struct
func NewGoMsHttpServer ¶
func NewGoMsHttpServer(ctx *Context, config *HttpServerConfig, grpcServer *GoMsGrpcServer) *GoMsHttpServer
Init GoMsHttpServer
func (*GoMsHttpServer) AddService ¶
func (o *GoMsHttpServer) AddService(service GoMsServiceInterface)
Add service in the local services list
func (*GoMsHttpServer) GracefulStop ¶
func (o *GoMsHttpServer) GracefulStop() error
Catch the SIG_TERM and exit cleanly
func (*GoMsHttpServer) Register ¶
func (o *GoMsHttpServer) Register(service GoMsServiceInterface) error
Register service on the http server
func (*GoMsHttpServer) SetExporter ¶
func (o *GoMsHttpServer) SetExporter(exporter *Exporter)
Set the exporter
func (*GoMsHttpServer) Start ¶
func (o *GoMsHttpServer) Start() error
Start the http server, ready for handle connexion
type GoMsMetricsInterface ¶
type GoMsMetricsInterface interface {
GetServiceName() string
}
Definition of GoMsMetricsInterface
type GoMsMiddlewareFunc ¶
type GoMsMiddlewareFunc func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
type GoMsServerGracefulStopableInterface ¶
type GoMsServerGracefulStopableInterface interface {
GracefulStop() error
}
Defition of ServerGracefulStopableInterface for http & grpc server graceful stop
type GoMsServerState ¶
type GoMsServerState int
Define the GRPC server state in ENUM
const ( Init GoMsServerState = 0 Boot GoMsServerState = 1 Listen GoMsServerState = 2 Ready GoMsServerState = 3 Error GoMsServerState = 4 Gracefull GoMsServerState = 5 Stop GoMsServerState = 6 )
type GoMsServiceFunc ¶
type GoMsServiceFunc func(*Context, string, ServiceConfig) GoMsServiceInterface
type GoMsServiceInterface ¶
type GoMsServiceInterface interface { GetName() string GetHandler() GoMsHandlerInterface SetClientManager(*GrpcClientManager) RegisterHttp(*GoMsHttpServer, string) error RegisterGrpc(*GoMsGrpcServer) GetClient(conn *grpc.ClientConn) any GetMiddlewaresConf() map[string][]string }
Definition of service interface for register http & grpc server
type GoMsStreamMiddlewareFunc ¶
type GoMsStreamMiddlewareFunc func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
type GrpcClientConfiguration ¶
type GrpcClientManager ¶
type GrpcClientManager struct {
// contains filtered or unexported fields
}
func NewGrpcClientManager ¶
func NewGrpcClientManager() *GrpcClientManager
func (*GrpcClientManager) AddClient ¶
func (o *GrpcClientManager) AddClient(name string, client any)
func (*GrpcClientManager) GetClient ¶
func (o *GrpcClientManager) GetClient(name string) (any, error)
func (*GrpcClientManager) GetConnection ¶
func (o *GrpcClientManager) GetConnection(name string) (*grpc.ClientConn, error)
func (*GrpcClientManager) InitConnections ¶
func (o *GrpcClientManager) InitConnections() error
type HttpServerConfig ¶
type HttpServerConfig struct { ServerConfig ReadTimeout int `yaml:"read-timeout"` WriteTimeout int `yaml:"write-timeout"` }
type JaegerConfig ¶
type JaegerConfig struct { Name string `yaml:"name"` Unsecure bool `yaml:"unsecure,omitempty"` Mode string `yaml:"mode"` Host string `yaml:"host,omitempty"` Port int `yaml:"port,omitempty"` Sampler struct { Type string `yaml:"type,omitempty"` Param int `yaml:"param,omitempty"` } `yaml:"sampler,omitempty"` Reporter struct { LogSpans bool `yaml:"log-spans,omitempty"` } `yaml:"reporter,omitempty"` }
type Jeager ¶
type Jeager struct { Config JaegerConfig Exporter sdktrace.SpanExporter TraceProvider trace.TracerProvider GracefullFunc func() }
type MetadataReaderWriter ¶
metadataReaderWriter sert de pont entre les métadonnées gRPC et le propagateur OpenTelemetry.
func (MetadataReaderWriter) ForeachKey ¶
func (mrw MetadataReaderWriter) ForeachKey(handler func(key string, val string) error) error
func (MetadataReaderWriter) Get ¶
func (mrw MetadataReaderWriter) Get(key string) string
func (MetadataReaderWriter) Keys ¶
func (mrw MetadataReaderWriter) Keys() []string
func (MetadataReaderWriter) Set ¶
func (mrw MetadataReaderWriter) Set(key string, value string)
type Middleware ¶
type Middleware interface { Apply(ctx context.Context, req interface{}) (context.Context, interface{}, error) Unary() grpc.UnaryServerInterceptor Stream() grpc.StreamServerInterceptor }
type ResponseWriterHandler ¶
type ResponseWriterHandler struct { http.ResponseWriter StatusCode int // contains filtered or unexported fields }
func NewResponseWriterHandler ¶
func NewResponseWriterHandler(w http.ResponseWriter) *ResponseWriterHandler
func (*ResponseWriterHandler) Finalize ¶
func (rw *ResponseWriterHandler) Finalize()
func (*ResponseWriterHandler) Flush ¶
func (rw *ResponseWriterHandler) Flush()
func (*ResponseWriterHandler) WriteHeader ¶
func (rw *ResponseWriterHandler) WriteHeader(code int)