server

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 57 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAccessLog

func SetAccessLog(accessLog AccessLog)

func SetPrometheusRecord added in v1.8.0

func SetPrometheusRecord(prometheusRecord PrometheusRecord)

func Start

func Start(s *Server)

func StreamAccess

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

func UnaryAccess

func UnaryAccess(conf *Config) func(
	context.Context, interface{},
	*grpc.UnaryServerInfo,
	grpc.UnaryHandler,
) (interface{}, error)

func Validator

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

Types

type AccessLog

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

type Config added in v1.6.0

type Config struct {
	ServerName  string
	Http        Http
	Http2       http2.Server
	Http3       *Http3 `json:"http3"`
	StopTimeout time.Duration
	StaticFs    []StaticFsConfig `json:"static_fs"`
	Gin         gini.Config      `json:"gin"`
	EnableCors  bool
	Cors        *cors.Options `json:"cors"`
	// Grpc options
	GRPCOptions               []grpc.ServerOption
	EnableGrpcWeb             bool
	GrpcWebOption             []web.Option `json:"grpc_web"`
	Trace, Prometheus, GenDoc bool
	BaseContext               func() context.Context
}

func (*Config) InitAfterInject added in v1.6.0

func (c *Config) InitAfterInject()

func (*Config) InitBeforeInject added in v1.6.0

func (c *Config) InitBeforeInject()

type ConvertContext

type ConvertContext func(r *http.Request) *http_context.Context

type CustomContext

type CustomContext func(c context.Context, r *http.Request) context.Context

type Http added in v1.8.0

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

type Http3 added in v1.8.0

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

type PrometheusRecord added in v1.8.0

type PrometheusRecord = func(ctxi *http_context.Context, uri, method string, code int)

type Server

type Server struct {
	Config *Config
	// 注册 grpc 服务
	GRPCHandler func(*grpc.Server)
	// 注册 grpc-gateway 服务
	GatewayHandler gateway.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 gateway.GatewayHandler, graphqlhandler graphql.ExecutableSchema) *Server

func (*Server) Start

func (s *Server) Start()

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