server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConsulRegistrar

func NewConsulRegistrar(opts *genericoptions.ConsulOptions) registry.Registrar

func NewEtcdRegistrar

func NewEtcdRegistrar(opts *genericoptions.EtcdOptions) registry.Registrar

func NewKratosLogger

func NewKratosLogger(id, name, version string) krtlog.Logger

func Serve

func Serve(ctx context.Context, srv Server) error

Serve starts the server and blocks until the context is canceled. It ensures the server is gracefully shut down when the context is done.

Types

type GRPCGatewayServer

type GRPCGatewayServer struct {
	// contains filtered or unexported fields
}

GRPCGatewayServer 代表一个 GRPC 网关服务器.

func NewGRPCGatewayServer

func NewGRPCGatewayServer(
	httpOptions *genericoptions.HTTPOptions,
	grpcOptions *genericoptions.GRPCOptions,
	tlsOptions *genericoptions.TLSOptions,
	registerHandler func(mux *runtime.ServeMux, conn *grpc.ClientConn) error,
) (*GRPCGatewayServer, error)

NewGRPCGatewayServer 创建一个新的 GRPC 网关服务器实例.

func (*GRPCGatewayServer) GracefulStop

func (s *GRPCGatewayServer) GracefulStop(ctx context.Context)

GracefulStop 优雅地关闭 GRPC 网关服务器.

func (*GRPCGatewayServer) RunOrDie

func (s *GRPCGatewayServer) RunOrDie()

RunOrDie 启动 GRPC 网关服务器并在出错时记录致命错误.

type GRPCServer

type GRPCServer struct {
	// contains filtered or unexported fields
}

GRPCServer 代表一个 GRPC 服务器.

func NewGRPCServer

func NewGRPCServer(
	grpcOptions *genericoptions.GRPCOptions,
	tlsOptions *genericoptions.TLSOptions,
	serverOptions []grpc.ServerOption,
	registerServer func(grpc.ServiceRegistrar),
) (*GRPCServer, error)

NewGRPCServer 创建一个新的 GRPC 服务器实例.

func (*GRPCServer) GracefulStop

func (s *GRPCServer) GracefulStop(ctx context.Context)

GracefulStop 优雅地关闭 GRPC 服务器.

func (*GRPCServer) RunOrDie

func (s *GRPCServer) RunOrDie()

RunOrDie 启动 GRPC 服务器并在出错时记录致命错误.

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

HTTPServer 代表一个 HTTP 服务器.

func NewHTTPServer

func NewHTTPServer(httpOptions *genericoptions.HTTPOptions, tlsOptions *genericoptions.TLSOptions, handler http.Handler) *HTTPServer

NewHTTPServer 创建一个新的 HTTP 服务器实例.

func (*HTTPServer) GracefulStop

func (s *HTTPServer) GracefulStop(ctx context.Context)

GracefulStop 优雅地关闭 HTTP 服务器.

func (*HTTPServer) RunOrDie

func (s *HTTPServer) RunOrDie()

RunOrDie 启动 HTTP 服务器并在出错时记录致命错误.

type KratosAppConfig

type KratosAppConfig struct {
	ID        string
	Name      string
	Version   string
	Metadata  map[string]string
	Registrar registry.Registrar
}

The purpose of defining the AppConfig is to demonstrate the usage of wire.Struct.

type KratosServer

type KratosServer struct {
	// contains filtered or unexported fields
}

The purpose of defining the AppConfig is to demonstrate the usage of wire.Struct.

func NewKratosServer

func NewKratosServer(cfg KratosAppConfig, servers ...transport.Server) (*KratosServer, error)

func (*KratosServer) GracefulStop

func (s *KratosServer) GracefulStop(ctx context.Context)

func (*KratosServer) RunOrDie

func (s *KratosServer) RunOrDie()

type Server

type Server interface {
	// RunOrDie 运行服务器,如果运行失败会退出程序(OrDie的含义所在).
	RunOrDie()
	// GracefulStop 方法用来优雅关停服务器。关停服务器时需要处理 context 的超时时间.
	GracefulStop(ctx context.Context)
}

Server 定义所有服务器类型的接口.

Jump to

Keyboard shortcuts

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