cherry

package module
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 57 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetMetricsRecord

func SetMetricsRecord(metricsRecord MetricsRecord)

func StreamAccess

func StreamAccess(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)

func StreamValidator

func StreamValidator(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)

func UnaryValidator

func UnaryValidator(
	ctx context.Context, req interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (resp interface{}, err error)

Types

type AccessLog

type AccessLog = func(ctxi *httpctx.Context, uri, method, body, result string, code int)

type Http

type Http struct {
	http.Server
	CertFile string
	KeyFile  string
}

type Http3

type Http3 struct {
	http3.Server
	CertFile string
	KeyFile  string
}

type HttpOption

type HttpOption struct {
	AccessLog          AccessLog
	ExcludeLogPrefixes []string
	IncludeLogPrefixes []string
	StaticFs           []StaticFsConfig
	Middlewares        []http.HandlerFunc
}

type IOption added in v1.16.7

type IOption interface {
	// contains filtered or unexported methods
}

type MetricsRecord

type MetricsRecord = func(ctxi *httpctx.Context, uri, method string, code int)

type Option added in v1.16.7

type Option func(server *Server)

func WithContext added in v1.16.7

func WithContext(ctx context.Context) Option

func WithCors added in v1.16.7

func WithCors(cors *cors.Options) Option

func WithGinHandler added in v1.16.7

func WithGinHandler(ginHandler func(*gin.Engine)) Option

func WithGraphqlHandler added in v1.16.7

func WithGraphqlHandler(graphqlHandler graphql.ExecutableSchema) Option

func WithGrpcHandler added in v1.16.7

func WithGrpcHandler(grpcHandler func(*grpc.Server)) Option

func WithGrpcOptions added in v1.16.7

func WithGrpcOptions(options ...grpc.ServerOption) Option

func WithGrpcWeb added in v1.16.7

func WithGrpcWeb(options ...web.Option) Option

func WithHttp3Addr added in v1.16.7

func WithHttp3Addr(addr string) Option

func WithHttpAddr added in v1.16.7

func WithHttpAddr(addr string) Option

func WithMiddlewares added in v1.16.7

func WithMiddlewares(middlewares ...http.HandlerFunc) Option

func WithName added in v1.16.7

func WithName(name string) Option

func WithOnStart added in v1.16.7

func WithOnStart(onStart func(context.Context)) Option

func WithOnStop added in v1.16.7

func WithOnStop(onStop func(context.Context)) Option

func WithStopTimeout added in v1.16.7

func WithStopTimeout(stopTimeout time.Duration) Option

func WithTelemetry added in v1.16.7

func WithTelemetry(telemetry TelemetryConfig) Option

type Server

type Server struct {
	Name        string
	Http        Http
	Http2       http2.Server
	Http3       *Http3
	StopTimeout time.Duration
	Gin         gini.Config
	EnableCors  bool
	Cors        *cors.Options
	Middlewares []http.HandlerFunc
	HttpOption  HttpOption
	// Grpc options
	GrpcOptions                                   []grpc.ServerOption
	EnableGrpcWeb                                 bool
	GrpcWebOptions                                []web.Option
	EnableTelemetry, EnableDebugApi, EnableApiDoc bool
	ApiDocUriPrefix, ApiDocDir                    string
	TelemetryConfig
	BaseContext context.Context
	// 注册 grpc 服务
	GrpcHandler func(*grpc.Server)
	// 注册 grpc-gateway 服务
	GatewayHandler grpc_gateway.GatewayHandler
	// 注册 gin 服务
	GinHandler func(*gin.Engine)
	// 注册 graphql 服务
	GraphqlHandler graphql.ExecutableSchema
	// 各种钩子函数
	OnStart func(context.Context)
	OnStop  func(context.Context)
}

func NewServer

func NewServer(options ...Option) *Server

func (*Server) AfterInject added in v1.16.17

func (s *Server) AfterInject()

func (*Server) BeforeInject added in v1.16.17

func (s *Server) BeforeInject()

implement initialize

func (*Server) Init added in v1.16.7

func (s *Server) Init()

func (*Server) Run added in v1.16.7

func (s *Server) Run()

func (*Server) UnaryAccess added in v1.16.7

func (s *Server) UnaryAccess(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func (*Server) WithOptions added in v1.16.7

func (s *Server) WithOptions(options ...Option) *Server

type StaticFsConfig

type StaticFsConfig struct {
	Prefix string
	Root   string
}

type TelemetryConfig

type TelemetryConfig struct {
	EnablePrometheus bool
	MetricsInterval  time.Duration
	// contains filtered or unexported fields
}

func (*TelemetryConfig) SetMeterProvider

func (c *TelemetryConfig) SetMeterProvider(meterProvider *sdkmetric.MeterProvider)

func (*TelemetryConfig) SetTextMapPropagator

func (c *TelemetryConfig) SetTextMapPropagator(propagator propagation.TextMapPropagator)

func (*TelemetryConfig) SetTracerProvider

func (c *TelemetryConfig) SetTracerProvider(tracerProvider *sdktrace.TracerProvider)

Directories

Path Synopsis
_example
protobuf/user
Package user is a reverse proxy.
Package user is a reverse proxy.
gateway
gin

Jump to

Keyboard shortcuts

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