app

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 11 Imported by: 0

README

engine

go-hamster框架的核心引擎

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCtx

func NewCtx(ctx context.Context) context.Context

func Run

func Run(opts ...Option) error

Types

type App

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

func NewApp

func NewApp(opts ...Option) *App

func (*App) Run

func (a *App) Run() (err error)

Run 运行引擎

type Ctx

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

func (*Ctx) Deadline

func (c *Ctx) Deadline() (deadline time.Time, ok bool)

func (*Ctx) Done

func (c *Ctx) Done() <-chan struct{}

func (*Ctx) Err

func (c *Ctx) Err() error

func (*Ctx) Value

func (c *Ctx) Value(key any) any

type Logger

type Logger interface {
	Log(format string, args ...any)
}

type Option

type Option func(opts *appOptions)

func WithCtx

func WithCtx(ctx context.Context) Option

func WithLogger

func WithLogger(logger Logger) Option

func WithPlugins

func WithPlugins(plugins ...Plugin) Option

func WithStopSignal

func WithStopSignal(signals ...os.Signal) Option

func WithStopTimeout

func WithStopTimeout(timeout time.Duration) Option

type Plugin

type Plugin interface {
	// Key 插件的key,需要保证在整个引擎中唯一
	Key() any
	// Register 引擎在注册插件时会执行该方法
	Register(ctx context.Context) error
	// Start 引擎完成准备后调用插件的 Start 方法进行运行插件内的服务(该方法会在协程中执行)
	Start(ctx context.Context) error
	// Stop 档引擎接受到停止的信号,会调用插件的 Stop 方法来告知插件应当停止内部服务(该方法会在携程中执行)
	// PS:上下文中将会携带超时信号,建议在 Stop 方法内部针对超时进行处理,以防止引擎无法正常停止
	Stop(ctx context.Context) error
	// Deregister 引擎在注销插件时会调用该方法,此时插件可以做一些资源释放的操作
	Deregister(ctx context.Context) error
	// Depends 告知引擎这个插件依赖哪些插件,如果所依赖的插件没有被注册,则应用会尝试自动注册
	Depends() []Plugin
}

type PluginAdapter

type PluginAdapter struct{}

func (PluginAdapter) Depends

func (a PluginAdapter) Depends() []Plugin

func (PluginAdapter) Deregister

func (a PluginAdapter) Deregister(_ context.Context) error

func (PluginAdapter) Register

func (a PluginAdapter) Register(_ context.Context) error

func (PluginAdapter) Start

func (a PluginAdapter) Start(_ context.Context) error

func (PluginAdapter) Stop

func (a PluginAdapter) Stop(_ context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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