core

package
v0.0.0-...-f257dc6 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MPL-2.0 Imports: 34 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddServerGracefulStop

func AddServerGracefulStop(server GoMsServerGracefulStopableInterface)

func Call

func Call[T any](ctx context.Context, cm *GrpcClientManager, serviceName, methodName string, params any) (T, error)

func CatchStopSignals

func CatchStopSignals() (done chan bool)

Catch SIG_TERM and exit propely

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

func RegisterServiceMap

func RegisterServiceMap[T GoMsServiceInterface](constructor func(*Context, string, ServiceConfig) T) func(*Context, string, ServiceConfig) T

func Trace

func Trace(ctx context.Context, name string, action string) (context.Context, trace.Span)

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 (*BaseMiddleware) Unary

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"`
}

func NewConfig

func NewConfig(filename string) (*Config, error)

type Context

type Context struct {
	Name   string
	Main   context.Context
	Jeager *Jeager
}

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

func NewExporter(ctx context.Context, host string, port int, path string, interval int) *Exporter

Initialize a exporter strucs

func (*Exporter) GracefulStop

func (o *Exporter) GracefulStop() error

func (*Exporter) HandleHttpHandler

func (o *Exporter) HandleHttpHandler(h http.Handler) http.Handler

Http Gateway middleware for handle metrics on all requests services

func (*Exporter) IncrRequests

func (o *Exporter) IncrRequests(code int, method string, path string)

Increment Gauge request by code, method and path

func (*Exporter) Start

func (o *Exporter) Start()

Start to expose /metrics

func (*Exporter) WatchedMetrics

func (o *Exporter) WatchedMetrics()

Not used yet Watch metrics in the interval time

type ExporterConfig

type ExporterConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Path     string `yaml:"path"`
	Interval int    `yaml:"interval"`
}

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

func (o *GoMsHttpServer) Handle(path string, mux *runtime.ServeMux)

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 GrpcClientConfiguration struct {
	Host    string
	Port    int
	Timeout time.Duration
}

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

func (o *GrpcClientManager) AddServer(name string, host string, port int, timeout time.Duration)

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()
}

func NewJeager

func NewJeager(ctx context.Context, name string, config JaegerConfig) *Jeager

type MetadataReaderWriter

type MetadataReaderWriter struct {
	metadata.MD
}

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

func (rw *ResponseWriterHandler) Write(b []byte) (int, error)

func (*ResponseWriterHandler) WriteHeader

func (rw *ResponseWriterHandler) WriteHeader(code int)

type ServerConfig

type ServerConfig struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

type ServiceConfig

type ServiceConfig struct {
	Http   bool                   `yaml:"http"`
	Config map[string]interface{} `yaml:"config,omitempty"`
}

Jump to

Keyboard shortcuts

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