server

package
v0.0.0-...-3e22abe Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxServerSN = 62*62*62 - 1
)

Variables

View Source
var (
	// DefaultMaxMsgSize define maximum message size that server can send
	// or receive.  Default value is 4MB.
	DefaultMaxMsgSize = 1024 * 1024 * 4
)

Functions

func SNBase62

func SNBase62[T utils.IntType](id T) string

SNBase62 62进制转换服务器id

func ServiceMethod

func ServiceMethod(m string) (string, string, error)

Types

type Handler

type Handler struct {
	Resource       string                 // resource name
	Collection     string                 // collection name
	Name           string                 // method name
	Rtype          reflect.Type           // 结构体
	Receiver       *reflect.Value         // receiver of method
	Method         reflect.Method         // method stub
	Query          reflect.Type           // 请求url query pram参数校验器
	Request        reflect.Type           // 请求参数
	QueryValidator *gojsonschema.Schema   // 请求参数校验器
	BodyValidator  *gojsonschema.Schema   // 请求载荷校验器
	Response       reflect.Type           // 返回参数
	Metadata       map[string]string      // 元数据
	Internal       bool                   // 内部rpc,不对外
	Hooks          []micro.PreExecuteHook // 执行前
}

func ExtractComponent

func ExtractComponent(component micro.Component) (map[string]*Handler, []*Handler)

ExtractComponent 解析组件 返回的map是可以走网关的Handlers 返回的列表是所有Handlers

func ExtractComponents

func ExtractComponents(components []micro.Component) (map[string]map[string]*Handler, []*Handler)

func (*Handler) BuildArgs

func (handler *Handler) BuildArgs(ctx context.Context, protocol string, query url.Values, body []byte) ([]reflect.Value, error)

BuildArgs rpc转发将请求转数据转化为反射调用参数

func (*Handler) Match

func (handler *Handler) Match(request, response string) bool

Match 判断请求头类型是否匹配

func (*Handler) UrlPath

func (handler *Handler) UrlPath() (resource, path, method string)

UrlPath 获取api path

type Option

type Option func(*Options)

func WithBroker

func WithBroker(broker broker.Broker) Option

func WithBrokerOpts

func WithBrokerOpts(options []broker.SubscribeOption) Option

func WithComponents

func WithComponents(components ...micro.Component) Option

func WithGrpcOptions

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

func WithListener

func WithListener(listener net.Listener) Option

func WithMax

func WithMax(version *micro.Version) Option

func WithMaxMsgSize

func WithMaxMsgSize(size int) Option

func WithMetadata

func WithMetadata(md map[string]string) Option

WithMetadata associated with the server

func WithMin

func WithMin(version *micro.Version) Option

func WithName

func WithName(name string) Option

WithName TODO 正则校验

func WithRegisterCheck

func WithRegisterCheck(f func(context.Context) error) Option

func WithRegisterCheckInterval

func WithRegisterCheckInterval(seconds time.Duration) Option

func WithRegistry

func WithRegistry(registry micro.Registry) Option

func WithServerId

func WithServerId(id uint64) Option

func WithVersion

func WithVersion(version *micro.Version) Option

func WithWaitGroup

func WithWaitGroup(wg *sync.WaitGroup) Option

type Options

type Options struct {
	//Broker broker.DefaultBroker,
	Id            uint32
	Name          string
	MaxMsgSize    int
	Version       *micro.Version // 当前服务版本号
	Min           *micro.Version // 支持的最小版本(默认当前版本)
	Max           *micro.Version // 支持的最大版本(默认当前版本)
	Interval      time.Duration
	Listener      net.Listener
	Broker        broker.Broker
	Registry      micro.Registry
	Components    []micro.Component
	GrpcOpts      []grpc.ServerOption
	BrokerOpts    []broker.SubscribeOption
	RegisterCheck func(context.Context) error
	WaitGroup     *sync.WaitGroup
	Metadata      map[string]string
}

func NewOptions

func NewOptions(name string) Options

type RPCServer

type RPCServer struct {
	tp.UnimplementedTransportServer

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts *Options) (*RPCServer, error)

func (*RPCServer) Call

func (g *RPCServer) Call(ctx context.Context, msg *tp.Message) (*tp.Message, error)

func (*RPCServer) Deregister

func (g *RPCServer) Deregister() error

func (*RPCServer) Register

func (g *RPCServer) Register() error

func (*RPCServer) Start

func (g *RPCServer) Start() error

func (*RPCServer) Stop

func (g *RPCServer) Stop() error

func (*RPCServer) Stream

func (g *RPCServer) Stream(stream tp.Transport_StreamServer) error

type Service

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

func (*Service) Handler

func (s *Service) Handler(service string, method string) *Handler

func (*Service) SubscriberAll

func (s *Service) SubscriberAll() error

func (*Service) UnsubscribeAll

func (s *Service) UnsubscribeAll() (errors []error)

Jump to

Keyboard shortcuts

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