server

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package server is an interface for a micro server

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAddress DefaultAddress
	DefaultAddress = ":0"
	// DefaultName DefaultName
	DefaultName = "go-server"
	// DefaultVersion DefaultVersion
	DefaultVersion = "1.0.0"
	// DefaultID DefaultID
	DefaultID = uuid.NewUUID().String()
)

Functions

This section is empty.

Types

type Message

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

Message RPC消息头

type Option

type Option func(*Options)

Option Option

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

Advertise The address to advertise for discovery - 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 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 registry.Registry) 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 {
	Registry  registry.Registry
	Metadata  map[string]string
	Name      string
	Address   string // use host:port nats_server.addr 不重要
	Advertise string // use host:port (优先) 不重要
	ID        string
	Version   string // module的版本

	RegisterInterval time.Duration
	RegisterTTL      time.Duration

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

Options Options

type Request

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

Request Request

type Server

type Server interface {
	ID() string // 模块服务ID
	Options() Options
	UpdMetadata(key, val string) // 更新元数据(正常需要等到下次注册时生效,如果要立即生效还需要调用ServiceRegister)
	OnInit(module app.IModule, settings *conf.ModuleSettings) error
	OnDestroy() error

	Register(id string, f any)   // 注册RPC方法
	RegisterGO(id string, f any) // 注册RPC方法
	SetListener(listener mqrpc.RPCListener)
	ServiceRegister() error   // 向Registry注册自己
	ServiceDeregister() error // 向Registry注销自己

	Start() error
	Stop() error

	String() string
}

Server Server

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(any) error
	Recv(any) 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