server

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, s RunnerInfo) context.Context

NewContext 创建一个携带 RunnerInfo 的 context

func Run

func Run(opts ...RunOption) error

Types

type RunOption

type RunOption func(*runner)

func WithAfterStart

func WithAfterStart(fn ...func(ctx context.Context) error) RunOption

func WithAfterStop

func WithAfterStop(fn ...func(ctx context.Context) error) RunOption

func WithBeforeStart

func WithBeforeStart(fn ...func(ctx context.Context) error) RunOption

func WithBeforeStop

func WithBeforeStop(fn ...func(ctx context.Context) error) RunOption

func WithContext

func WithContext(ctx context.Context) RunOption

func WithEndpoints

func WithEndpoints(endpoints []string) RunOption

func WithID

func WithID(id string) RunOption

func WithLogger

func WithLogger(logger *zap.Logger) RunOption

func WithMetadata

func WithMetadata(metadata map[string]string) RunOption

func WithName

func WithName(name string) RunOption

func WithServers

func WithServers(server ...Server) RunOption

func WithSignals added in v0.1.13

func WithSignals(sigs ...os.Signal) RunOption

func WithStopTimeout

func WithStopTimeout(stopTimeout time.Duration) RunOption

func WithVersion

func WithVersion(version string) RunOption

type Runner

type Runner interface {
	Run() error
	Stop() error
}

func NewRunner

func NewRunner(opts ...RunOption) Runner

type RunnerInfo

type RunnerInfo interface {
	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Endpoints() []string
}

func FromContext

func FromContext(ctx context.Context) (s RunnerInfo, ok bool)

FromContext 从 context 中获取 RunnerInfo

type Server

type Server interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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