server

package
v1.12.11 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 56 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAccessLog

func SetAccessLog(accessLog AccessLog)

func SetMetricsRecord added in v1.0.6

func SetMetricsRecord(metricsRecord MetricsRecord)

func Start

func Start(s *Server)

func StreamAccess

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

func StreamValidator added in v1.5.11

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

func UnaryAccess

func UnaryAccess(conf *Config) grpc.UnaryServerInterceptor

func UnaryValidator added in v1.5.11

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 Config

type Config struct {
	ServerName  string
	Http        Http
	Http2       http2.Server
	Http3       *Http3 `json:"http3"`
	StopTimeout time.Duration
	Gin         gini.Config `json:"gin"`
	EnableCors  bool
	Cors        *cors.Options `json:"cors"`
	Middlewares []http.HandlerFunc
	HttpOption  HttpOption
	// Grpc options
	GrpcOptions                          []grpc.ServerOption
	EnableGrpcWeb                        bool
	GrpcWebOption                        []web.Option `json:"grpc_web"`
	EnableTracing, EnableMetrics, GenDoc bool
	BaseContext                          func() context.Context
}

func NewConfig added in v1.4.0

func NewConfig() *Config

func (*Config) Init added in v1.4.0

func (c *Config) Init()

type Http

type Http struct {
	http.Server
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`
}

type Http3

type Http3 struct {
	http3.Server
	CertFile string `json:"cert_file"`
	KeyFile  string `json:"key_file"`
}

type HttpOption added in v1.0.6

type HttpOption struct {
	ExcludeLogPrefixes []string
	IncludeLogPrefixes []string
	StaticFs           []StaticFsConfig `json:"static_fs"`
	Middlewares        []http.HandlerFunc
}

type MetricsRecord added in v1.0.6

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

type Server

type Server struct {
	Config *Config
	// 注册 grpc 服务
	GrpcHandler func(*grpc.Server)
	// 注册 grpc-gateway 服务
	GatewayHandler runtime.GatewayHandler
	// 注册 gin 服务
	GinHandler func(*gin.Engine)
	// 注册 graphql 服务
	GraphqlHandler graphql.ExecutableSchema

	// 各种钩子函数
	OnBeforeStart func(context.Context)
	OnAfterStart  func(context.Context)
	OnBeforeStop  func(context.Context)
	OnAfterStop   func(context.Context)
}

func NewServer

func NewServer(config *Config, ginhandler func(*gin.Engine), grpchandler func(*grpc.Server), gatewayhandler runtime.GatewayHandler, graphqlhandler graphql.ExecutableSchema) *Server

func (*Server) Start

func (s *Server) Start()

type ServerOption added in v1.0.6

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

TODO

type StaticFsConfig

type StaticFsConfig struct {
	Prefix string
	Root   string
}

Jump to

Keyboard shortcuts

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