server

package
v0.0.0-...-817968b Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundCodec = errors.New("not found codec")
	ErrNoBinder      = errors.New("no binder")
)

some error

Functions

func GetRequest

func GetRequest(ctx context.Context) netx.Request

GetRequest 从Context中获取netx.Request

func GetResponseHeader

func GetResponseHeader(ctx context.Context) netx.Header

GetResponseHeader 从Context中获取response header

func New

func New(opts ...Option) netx.Server

New 创建Server

func NewRouter

func NewRouter() netx.Router

NewRouter 创建router

func SetResponseHeader

func SetResponseHeader(ctx context.Context, header netx.Header)

SetResponseHeader 设置Response header

Types

type BindUnmarshaler

type BindUnmarshaler interface {
	// UnmarshalParam decodes and assigns a value from an form or query param.
	UnmarshalParam(param string) error
}

BindUnmarshaler is the interface used to wrap the UnmarshalParam method. Types that don't implement this, but do implement encoding.TextUnmarshaler will use that interface instead.

type Binder

type Binder interface {
	Bind(ctx context.Context, req netx.Request, out interface{}) error
}

Binder is the interface that wraps the Bind method.

type Option

type Option func(o *Options)

func WithAddr

func WithAddr(addr string) Option

func WithBinder

func WithBinder(b Binder) Option

func WithCodec

func WithCodec(v netx.CodecType) Option

func WithDetector

func WithDetector(d netx.Detector) Option

func WithExec

func WithExec(e netx.Executor) Option

func WithID

func WithID(id string) Option

func WithMetadata

func WithMetadata(v map[string]string) Option

func WithModules

func WithModules(m ...netx.Module) Option

func WithName

func WithName(name string) Option

func WithNode

func WithNode(n *registry.Node) Option

func WithRegistry

func WithRegistry(r registry.Registry) Option

func WithRouter

func WithRouter(r netx.Router) Option

func WithSignals

func WithSignals(s ...os.Signal) Option

func WithTran

func WithTran(t netx.Tran) Option

func WithValidator

func WithValidator(v Validator) Option

func WithVersion

func WithVersion(v string) Option

type Options

type Options struct {
	ID          string            // 唯一ID,如果不指定,则随机生成
	Name        string            // 服务名
	Version     string            // 服务版本
	Metadata    map[string]string // Meta
	Addr        string            // 监听地址
	Tran        netx.Tran         // Transport
	Detector    netx.Detector     // 协议探测,默认自动探测
	Router      netx.Router       // 路由
	Exec        netx.Executor     // 调度器,默认每条消息一个go routine并发执行
	Node        *registry.Node    // node配置信息
	Registry    registry.Registry // 服务注册
	RegistryTTL time.Duration     // 注册过期时间
	Signals     []os.Signal       // 需要监听的事件,默认syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT
	Modules     []netx.Module     // 扩展模块
	Binder      Binder            //
	Validator   Validator         //
	Codec       netx.CodecType    // 默认编解码协议
}

Options 可选配置参数

type Validator

type Validator interface {
	Validate(ctx context.Context, msg interface{}) error
}

Validator is the interface that wraps the Validate function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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