server

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MulanPSL-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAddress DefaultAddress
	DefaultAddress = ":19000"
	// DefaultName DefaultName
	DefaultName = "go-server"
	// DefaultVersion DefaultVersion
	DefaultVersion = "1.0.0"
	// DefaultID DefaultID
	DefaultID = guuid.New().String()
)

Functions

This section is empty.

Types

type BindFuc

type BindFuc func(*grpc.Server)

type Message

type Message interface {
	Topic() string
	Payload() interface{}
	ContentType() string
}

Message RPC消息头

type NewRPCServer

type NewRPCServer func() (RPCServerI, error)

type Option

type Option func(*Options)

Option Option

func Address

func Address(a string) Option

Address to bind to - host:port

func ID

func ID(id string) Option

ID Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the server

func Name

func Name(n string) Option

Name Server name

func Port

func Port(a int) Option

Port

func RPCBind

func RPCBind(fnc func(*grpc.Server)) Option

RPCBind Register the service RPC

func RegisterInterval

func RegisterInterval(t time.Duration) Option

RegisterInterval specifies the interval on which to re-register

func RegisterTTL

func RegisterTTL(t time.Duration) Option

RegisterTTL Register the service with a TTL

func Registry

func Registry(r reg.Registry) Option

Registry used for discovery

func RegistryEnable

func RegistryEnable(status bool) Option

Registry used for discovery

func Version

func Version(v string) Option

Version of the service

func Wait

func Wait(b bool) Option

Wait tells the server to wait for requests to finish before exiting

type Options

type Options struct {
	RegistryEnable bool
	Registry       reg.Registry
	Metadata       map[string]string
	Name           string
	Address        string
	Port           int
	ID             string
	Version        string

	RegisterInterval time.Duration
	RegisterTTL      time.Duration
	//RPCBind 服务端grpc注册
	RPCBind func(*grpc.Server)
	Context context.Context
}

Options Options

type RPCClient

type RPCClient interface {
	Call(ctx context.Context, _func string, params ...interface{}) (interface{}, string)
	CallArgs(ctx context.Context, _func string, ArgsType []string, args [][]byte) (interface{}, string)
}

RPCClient 客户端定义

type RPCServer

type RPCServer struct {
	Server *grpc.Server

	ServerCert string
	ServerKey  string
	// contains filtered or unexported fields
}

func (*RPCServer) Done

func (R *RPCServer) Done() (err error)

func (*RPCServer) GetRpc

func (R *RPCServer) GetRpc() *grpc.Server

func (*RPCServer) SetRpc

func (R *RPCServer) SetRpc(sv *grpc.Server)

type RPCServerI

type RPCServerI interface {
	GetRpc() *grpc.Server
	SetRpc(sv *grpc.Server)
	Done() (err error)
}

RPCServerI 服务定义

type Request

type Request interface {
	Service() string
	Method() string
	ContentType() string
	Request() interface{}
	// indicates whether the request will be streamed
	Stream() bool
}

Request Request

type Server

type Server interface {
	Options() Options
	OnInit(*glog.Logger) error
	Init(...Option) error
	Register(f func(s *grpc.Server))
	ServiceRegister() error
	ServiceDeregister() error
	Start(bind BindFuc, tracing bool) error
	Stop() error
	OnDestroy() error
	String() string
	ID() string
	Port() int
	GetRpcServer() *grpc.Server
}

Server is a simple micro server abstraction

func NewServer

func NewServer(opt ...Option) Server

NewServer returns a new server with options passed in

type Stream

type Stream interface {
	Context() context.Context
	Request() Request
	Send(interface{}) error
	Recv(interface{}) error
	Error() error
	Close() error
}

Stream represents a stream established with a client. A stream can be bidirectional which is indicated by the request. The last error will be left in Error(). EOF indicated end of the stream.

Jump to

Keyboard shortcuts

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