module

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package module 提供模块管理的相关功能

Index

Constants

This section is empty.

Variables

View Source
var ErrInited = errors.New("模块已经初始化")

ErrInited 当模块被多次初始化时返回此错误

Functions

This section is empty.

Types

type InstallFunc added in v0.32.0

type InstallFunc func(*Server)

InstallFunc 安装模块的函数签名

type JobFunc added in v0.26.0

type JobFunc = scheduled.JobFunc

JobFunc 定时任务执行的函数

type Module

type Module struct {
	Tag
	Name        string
	Description string
	Deps        []string
	// contains filtered or unexported fields
}

Module 表示模块信息

模块仅作为在初始化时在代码上的一种分类,一旦初始化完成, 则不再有模块的概念,修改模块的相关属性,也不会对代码有实质性的改变。

func (*Module) AddAt added in v0.26.0

func (m *Module) AddAt(title string, f JobFunc, spec string, delay bool)

AddAt 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; spec 指定的时间点; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Module) AddCron added in v0.26.0

func (m *Module) AddCron(title string, f JobFunc, spec string, delay bool)

AddCron 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; spec cron 表达式,支持秒; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Module) AddService added in v0.25.0

func (m *Module) AddService(f ServiceFunc, title string)

AddService 添加新的服务

f 表示服务的运行函数; title 是对该服务的简要说明。

func (*Module) AddTicker added in v0.26.0

func (m *Module) AddTicker(title string, f JobFunc, dur time.Duration, imm, delay bool)

AddTicker 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; imm 是否立即执行一次该任务; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Module) Delete

func (m *Module) Delete(path string, h context.HandlerFunc) *Module

Delete 指定个 DELETE 请求处理

func (*Module) Get

func (m *Module) Get(path string, h context.HandlerFunc) *Module

Get 指定一个 GET 请求

func (*Module) Handle

func (m *Module) Handle(path string, h context.HandlerFunc, method ...string) *Module

Handle 添加路由项

func (*Module) NewTag added in v0.16.1

func (m *Module) NewTag(tag string) *Tag

NewTag 为当前模块生成特定名称的子模块

若已经存在,则直接返回该子模块。

Tag 是依赖关系与当前模块相同,但是功能完全独立的模块, 一般用于功能更新等操作。

func (*Module) Options added in v0.32.0

func (m *Module) Options(path, allow string) *Module

Options 指定个 OPTIONS 请求处理

func (*Module) Patch

func (m *Module) Patch(path string, h context.HandlerFunc) *Module

Patch 指定个 PATCH 请求处理

func (*Module) Post

func (m *Module) Post(path string, h context.HandlerFunc) *Module

Post 指定个 POST 请求处理

func (*Module) Prefix

func (m *Module) Prefix(prefix string) *Prefix

Prefix 声明一个 Prefix 实例

func (*Module) Put

func (m *Module) Put(path string, h context.HandlerFunc) *Module

Put 指定个 PUT 请求处理

func (*Module) Resource added in v0.32.0

func (m *Module) Resource(pattern string) *Resource

Resource 生成资源项

type Prefix

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

Prefix 管理带有统一前缀的路由项

func (*Prefix) Delete

func (p *Prefix) Delete(path string, h context.HandlerFunc) *Prefix

Delete 指定个 DELETE 请求处理

func (*Prefix) Get

func (p *Prefix) Get(path string, h context.HandlerFunc) *Prefix

Get 指定一个 GET 请求

func (*Prefix) Handle

func (p *Prefix) Handle(path string, h context.HandlerFunc, method ...string) *Prefix

Handle 添加路由项

func (*Prefix) Module

func (p *Prefix) Module() *Module

Module 返回关联的模块实例

func (*Prefix) Options added in v0.32.0

func (p *Prefix) Options(path, allow string) *Prefix

Options 指定个 OPTIONS 请求处理

func (*Prefix) Patch

func (p *Prefix) Patch(path string, h context.HandlerFunc) *Prefix

Patch 指定个 PATCH 请求处理

func (*Prefix) Post

func (p *Prefix) Post(path string, h context.HandlerFunc) *Prefix

Post 指定个 POST 请求处理

func (*Prefix) Put

func (p *Prefix) Put(path string, h context.HandlerFunc) *Prefix

Put 指定个 PUT 请求处理

func (*Prefix) Resource added in v0.32.0

func (p *Prefix) Resource(pattern string) *Resource

Resource 生成资源项

type Resource added in v0.32.0

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

Resource 以资源地址为对象的路由配置

func (*Resource) Delete added in v0.32.0

func (r *Resource) Delete(h context.HandlerFunc) *Resource

Delete 指定个 DELETE 请求处理

func (*Resource) Get added in v0.32.0

func (r *Resource) Get(h context.HandlerFunc) *Resource

Get 指定一个 GET 请求

func (*Resource) Handle added in v0.32.0

func (r *Resource) Handle(h context.HandlerFunc, method ...string) *Resource

Handle 添加路由项

func (*Resource) Options added in v0.32.0

func (r *Resource) Options(allow string) *Resource

Options 指定个 OPTIONS 请求处理

func (*Resource) Patch added in v0.32.0

func (r *Resource) Patch(h context.HandlerFunc) *Resource

Patch 指定个 PATCH 请求处理

func (*Resource) Post added in v0.32.0

func (r *Resource) Post(h context.HandlerFunc) *Resource

Post 指定个 POST 请求处理

func (*Resource) Put added in v0.32.0

func (r *Resource) Put(h context.HandlerFunc) *Resource

Put 指定个 PUT 请求处理

type Server added in v0.32.0

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

Server 提供模块管理功能

func NewServer added in v0.32.0

func NewServer(server *context.Server, plugin string) (*Server, error)

NewServer 声明一个新的 Server 实例

func (*Server) AddService added in v0.32.0

func (srv *Server) AddService(f ServiceFunc, title string)

AddService 添加新的服务

f 表示服务的运行函数; title 是对该服务的简要说明。

func (*Server) Init added in v0.32.0

func (srv *Server) Init(tag string, info *log.Logger) error

Init 初始化模块

若指定了 tag 参数,则只初始化与该标签相关联的内容。

一旦初始化完成,则不再接受添加新模块,也不能再次进行初始化。 Server 和 Module 之中的大部分功能将失去操作意义,比如 Server.NewModule 虽然能添加新模块到 Server,但并不能真正初始化新的模块并挂载。

func (*Server) Modules added in v0.32.0

func (srv *Server) Modules() []*Module

Modules 当前系统使用的所有模块信息

func (*Server) NewModule added in v0.32.0

func (srv *Server) NewModule(name, desc string, deps ...string) *Module

NewModule 声明一个新的模块

name 模块名称,需要全局唯一; desc 模块的详细信息; deps 表示当前模块的依赖模块名称,可以是插件中的模块名称。

func (*Server) RunServices added in v0.32.0

func (srv *Server) RunServices()

RunServices 运行所有的服务

func (*Server) Scheduled added in v0.32.0

func (srv *Server) Scheduled() *scheduled.Server

Scheduled 获取 scheduled.Server 实例

func (*Server) Services added in v0.32.0

func (srv *Server) Services() []*Service

Services 返回所有的服务列表

func (*Server) StopServices added in v0.32.0

func (srv *Server) StopServices()

StopServices 停止服务

func (*Server) Tags added in v0.32.0

func (srv *Server) Tags() map[string][]string

Tags 返回所有的子模块名称

键名为模块名称,键值为该模块下的标签列表。

type Service added in v0.25.0

type Service struct {
	Title string
	// contains filtered or unexported fields
}

Service 服务模型

func (*Service) Err added in v0.25.0

func (srv *Service) Err() error

Err 上次的错误信息,不会清空。

func (*Service) Run added in v0.25.0

func (srv *Service) Run()

Run 开始执行该服务

func (*Service) State added in v0.25.0

func (srv *Service) State() ServiceState

State 获取当前服务的状态

func (*Service) Stop added in v0.25.0

func (srv *Service) Stop()

Stop 停止服务

type ServiceFunc added in v0.25.0

type ServiceFunc func(ctx context.Context) error

ServiceFunc 服务实际需要执行的函数

实现者需要正确处理 ctx.Done 事件,调用者可能会主动取消函数执行; 如果是通 ctx 取消的,应该返回其错误信息。

type ServiceState added in v0.25.0

type ServiceState int8

ServiceState 服务的状态值

const (
	ServiceStopped ServiceState = iota // 当前处理停止状态,默认状态
	ServiceRunning                     // 正在运行
	ServiceFailed                      // 出错,不再执行后续操作
)

几种可能的状态值

func (ServiceState) String added in v0.32.0

func (s ServiceState) String() string

type Tag added in v0.26.0

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

Tag 表示与特定标签相关联的初始化函数列表

依附于模块,共享模块的依赖关系。

一般是各个模块下的安装脚本使用。

func (*Tag) AddInit added in v0.26.0

func (t *Tag) AddInit(f func() error, title string) *Tag

AddInit 添加一个初始化函数

title 该初始化函数的名称。

Jump to

Keyboard shortcuts

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