appmgr

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const KeepaliveMinTime = 10 * time.Second
View Source
const KeepaliveTime = 1 * time.Minute
View Source
const KeepaliveTimeout = 20 * time.Second
View Source
const ServerConnMaxAge = time.Duration(math.MaxInt64)
View Source
const ServerConnMaxAgeGrace = time.Duration(math.MaxInt64)
View Source
const ServerConnMaxIdle = time.Duration(math.MaxInt64)

Variables

This section is empty.

Functions

func SetContextService

func SetContextService(ctx context.Context, service Service) context.Context

func SetGinContextService

func SetGinContextService(ctx *gin.Context, service Service)

Types

type App

type App interface {
	// Init initializes application by config
	// Any error will cause process exit with error status
	Init()

	// Run runs application
	Run() error

	// RunOrExit runs application and exits with error status if got any error
	RunOrExit()

	// RegisterMiddleware registers a middleware with name in application
	// The middlewares need to be registered before calling App.Init
	RegisterMiddleware(string, Middleware)

	// AddJob adds job func with name into application
	AddJob(string, func(ctx context.Context) error)

	// GetContext gets context of application
	GetContext() context.Context

	// GetService gets service object by name
	GetService(string) Service

	// GetGrpcClientConn gets grpc client conn interface by name
	GetGrpcClientConn(string) grpc.ClientConnInterface

	// GetGrpcClientConns gets grpc client conn interfaces by name for different endpoints
	GetGrpcClientConns(string) []grpc.ClientConnInterface

	// GetDatabaseClient gets database gorm client by name
	GetDatabaseClient(string) *gorm.DB

	// GetDatabaseSqlxClient gets database mssqlx client by name
	GetDatabaseSqlxClient(string) *mssqlx.DBs

	// GetCacheClient gets cache client by name
	GetCacheClient(string) cache.Client

	// GetPulsarClient gets Pulsar client by name
	GetPulsarClient(string) pulsar.Client
}

func NewApp

func NewApp(info *AppInfo) App

type AppConfig

type AppConfig struct {
	Name       string            `json:"name" mapstructure:"name"`
	Observable ObservableConfig  `json:"observable" mapstructure:"observable"`
	Services   []ServiceConfig   `json:"services" mapstructure:"services"`
	Jobs       []string          `json:"jobs" mapstructure:"jobs"`
	Clients    ClientsConfig     `json:"clients" mapstructure:"clients"`
	Databases  []database.Config `json:"databases" mapstructure:"databases"`
	Caches     []cache.Config    `json:"caches" mapstructure:"caches"`
	Pulsars    []pulsar.Config   `json:"pulsar" mapstructure:"pulsars"`
}

type AppInfo

type AppInfo struct {
	Name        string
	Version     string
	Description string
}

type ClientManager

type ClientManager interface {
	GetGrpcClientConn(string) grpc.ClientConnInterface
	GetGrpcClientConns(string) []grpc.ClientConnInterface
}

type ClientsConfig

type ClientsConfig struct {
	Grpc GrpcConfig `json:"grpc" mapstructure:"grpc"`
}

type DatabaseManager

type DatabaseManager interface {
	GetDatabaseClient(string) *gorm.DB
	GetDatabaseSqlxClient(string) *mssqlx.DBs
}

type EndpointsConfig

type EndpointsConfig struct {
	Grpc string `json:"grpc" mapstructure:"grpc"`
	Http string `json:"http" mapstructure:"http"`
}

type GrpcConfig

type GrpcConfig struct {
	Middlewares []interface{}      `json:"middlewares" mapstructure:"middlewares"`
	Servers     []GrpcServerConfig `json:"servers" mapstructure:"servers"`
}

type GrpcSecurityConfig

type GrpcSecurityConfig struct {
	Cert string `json:"cert" mapstructure:"cert"`
	Key  string `json:"key" mapstructure:"key"`
	Ca   string `json:"ca" mapstructure:"ca"`
}

func (*GrpcSecurityConfig) Resolve

func (c *GrpcSecurityConfig) Resolve()

type GrpcServerConfig

type GrpcServerConfig struct {
	Name     string             `json:"name" mapstructure:"name" validate:"required"`
	Endpoint string             `json:"endpoint" mapstructure:"endpoint" validate:"required"`
	Security GrpcSecurityConfig `json:"security" mapstructure:"security"`
}

type IContextGetter

type IContextGetter interface {
	Value(key interface{}) interface{}
}

type Middleware

type Middleware interface {
	GinHandler(map[string]interface{}) gin.HandlerFunc
	GrpcServerInterceptor(map[string]interface{}) (grpc.UnaryServerInterceptor, grpc.StreamServerInterceptor)
	GrpcClientInterceptor(map[string]interface{}) (grpc.UnaryClientInterceptor, grpc.StreamClientInterceptor)
}

func NewAccessControlMiddleware

func NewAccessControlMiddleware() Middleware

func NewCompressMiddleware

func NewCompressMiddleware() Middleware

func NewContextLoggerMiddleware

func NewContextLoggerMiddleware() Middleware

func NewContextTagsMiddleware

func NewContextTagsMiddleware() Middleware

func NewCorsMiddleware

func NewCorsMiddleware() Middleware

func NewLogRequestMiddleware

func NewLogRequestMiddleware() Middleware

func NewMetricsMiddleware

func NewMetricsMiddleware() Middleware

func NewOpenTracingMiddleware

func NewOpenTracingMiddleware() Middleware

func NewRecoveryMiddleware

func NewRecoveryMiddleware() Middleware

func NewRequestValidationMiddleware

func NewRequestValidationMiddleware() Middleware

func NewServiceContextMiddleware

func NewServiceContextMiddleware(service Service) Middleware

type ObservableConfig

type ObservableConfig struct {
	Endpoints EndpointsConfig `json:"endpoints" mapstructure:"endpoints" validate:"required"`
	Modules   []string        `json:"modules" mapstructure:"modules"`
}

type ObservableService

type ObservableService interface {
	GetContext() context.Context
	Run() error
	Wait()
}

type Service

type Service interface {
	GetContext() context.Context
	GetName() string
	GetApp() App
	GetGrpcEndpoint() string
	GetHttpEndpoint() string
	GetGrpcServiceRegistrar() grpc.ServiceRegistrar
	GetGrpcChannelClient() grpc.ClientConnInterface
	GetServeMux() *runtime.ServeMux
	GetGinRouter() gin.IRoutes
	AddHealthCheck(name string, check health.CheckFunc)
	Run() error
	Wait()
}

func GetContextService

func GetContextService(ctx IContextGetter) Service

type ServiceConfig

type ServiceConfig struct {
	Name        string                `json:"name" mapstructure:"name" validate:"required"`
	Endpoints   EndpointsConfig       `json:"endpoints" mapstructure:"endpoints" validate:"required"`
	Security    ServiceSecurityConfig `json:"security" mapstructure:"security"`
	Middlewares []interface{}         `json:"middlewares" mapstructure:"middlewares"`
}

type ServiceSecurityConfig

type ServiceSecurityConfig struct {
	Grpc GrpcSecurityConfig `json:"grpc" mapstructure:"grpc"`
}

Jump to

Keyboard shortcuts

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