srv

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package srv is the Go implementation of server, which is designed to be high-performance, everything-pluggable and easy for testing.

Index

Constants

This section is empty.

Variables

DefaultServerCloseSIG are signals that close server.

View Source
var New = func(opts *Options) Service {
	s := &service{
		opts:     opts,
		handlers: make(map[string]Handler),
	}

	s.opts.TransportOptions.Handler = s

	s.ctx, s.cancel = context.WithCancel(context.Background())
	return s
}

New create service

Functions

func Config

func Config() *config

Config returns the common Config.

func IsClosing

func IsClosing() bool

func SetClosing

func SetClosing()

Types

type Description

type Description struct {
	Name  string
	Funcs []Func
}

Description 服务描述信息

type Func

type Func struct {
	Name    string
	Handler Handler
}

Func provides the information of an RPC Method.

type Handler

type Handler func(ctx context.Context,
	reqHeader *proto.RequestHeader, reqBodyBuf []byte) (rsp interface{}, err error)

Handler is the default handler.

type Options

type Options struct {
	Machine     string        // 机器名(容器名)
	Env         string        // 环境名
	ServiceName string        // 服务名
	Address     string        // 监听地址
	Protocol    string        // 服务协议,如 rpc、http、web
	Timeout     time.Duration // 请求处理超时时间

	Registry         naming.Registry     // 名字服务注册接口
	Transport        transport.Transport // 传输层
	TransportOptions transport.Options   // 传输层配置
	Codec            codec.Codec         // 编解码接口

	CloseWaitTime    time.Duration // 注销名字服务之后的等待时间,让名字服务更新实例列表。 (单位 ms) 最大: 10s.
	MaxCloseWaitTime time.Duration // 进程结束之前等待请求完成的最大等待时间。(单位 ms)
}

Options are server side options.

type Server

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

Server is a server. One process, one server. A server may offer one or more services.

func NewServer

func NewServer(serverDesc *Description) *Server

NewServer 新建服务

func (*Server) Close

func (s *Server) Close()

func (*Server) Serve

func (s *Server) Serve() error

Serve implements Service, starting all services that belong to the server.

type Service

type Service interface {
	// Register registers service handle func
	Register(funcs []Func) error
	// Serve start serving.
	Serve() error
	// Close stop serving.
	Close(chan struct{})
}

Service is the interface that provides services.

Directories

Path Synopsis
Package codec defines the business communication protocol of packing and unpacking.
Package codec defines the business communication protocol of packing and unpacking.
Package registry registers servers.
Package registry registers servers.
Package transport is the network client layer.
Package transport is the network client layer.
http
Package http provides support for http protocol by default, provides rpc server with http protocol, and provides rpc database for calling http protocol.
Package http provides support for http protocol by default, provides rpc server with http protocol, and provides rpc database for calling http protocol.
rpc

Jump to

Keyboard shortcuts

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