Documentation
¶
Overview ¶
Package module 提供模块管理的相关功能
Index ¶
- Variables
- type InstallFunc
- type JobFunc
- type Module
- func (m *Module) AddAt(title string, f JobFunc, spec string, delay bool)
- func (m *Module) AddCron(title string, f JobFunc, spec string, delay bool)
- func (m *Module) AddService(f ServiceFunc, title string)
- func (m *Module) AddTicker(title string, f JobFunc, dur time.Duration, imm, delay bool)
- func (m *Module) Delete(path string, h context.HandlerFunc) *Module
- func (m *Module) Get(path string, h context.HandlerFunc) *Module
- func (m *Module) Handle(path string, h context.HandlerFunc, method ...string) *Module
- func (m *Module) NewTag(tag string) *Tag
- func (m *Module) Options(path, allow string) *Module
- func (m *Module) Patch(path string, h context.HandlerFunc) *Module
- func (m *Module) Post(path string, h context.HandlerFunc) *Module
- func (m *Module) Prefix(prefix string) *Prefix
- func (m *Module) Put(path string, h context.HandlerFunc) *Module
- func (m *Module) Resource(pattern string) *Resource
- type Prefix
- func (p *Prefix) Delete(path string, h context.HandlerFunc) *Prefix
- func (p *Prefix) Get(path string, h context.HandlerFunc) *Prefix
- func (p *Prefix) Handle(path string, h context.HandlerFunc, method ...string) *Prefix
- func (p *Prefix) Module() *Module
- func (p *Prefix) Options(path, allow string) *Prefix
- func (p *Prefix) Patch(path string, h context.HandlerFunc) *Prefix
- func (p *Prefix) Post(path string, h context.HandlerFunc) *Prefix
- func (p *Prefix) Put(path string, h context.HandlerFunc) *Prefix
- func (p *Prefix) Resource(pattern string) *Resource
- type Resource
- func (r *Resource) Delete(h context.HandlerFunc) *Resource
- func (r *Resource) Get(h context.HandlerFunc) *Resource
- func (r *Resource) Handle(h context.HandlerFunc, method ...string) *Resource
- func (r *Resource) Options(allow string) *Resource
- func (r *Resource) Patch(h context.HandlerFunc) *Resource
- func (r *Resource) Post(h context.HandlerFunc) *Resource
- func (r *Resource) Put(h context.HandlerFunc) *Resource
- type Server
- func (srv *Server) AddService(f ServiceFunc, title string)
- func (srv *Server) Init(tag string, info *log.Logger) error
- func (srv *Server) Modules() []*Module
- func (srv *Server) NewModule(name, desc string, deps ...string) *Module
- func (srv *Server) RunServices()
- func (srv *Server) Scheduled() *scheduled.Server
- func (srv *Server) Services() []*Service
- func (srv *Server) StopServices()
- func (srv *Server) Tags() map[string][]string
- type Service
- type ServiceFunc
- type ServiceState
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ErrInited = errors.New("模块已经初始化")
ErrInited 当模块被多次初始化时返回此错误
Functions ¶
This section is empty.
Types ¶
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
AddAt 添加新的定时任务
f 表示服务的运行函数; title 是对该服务的简要说明; spec 指定的时间点; delay 是否在任务执行完之后,才计算下一次的执行时间点。
func (*Module) AddCron ¶ added in v0.26.0
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
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) NewTag ¶ added in v0.16.1
NewTag 为当前模块生成特定名称的子模块
若已经存在,则直接返回该子模块。
Tag 是依赖关系与当前模块相同,但是功能完全独立的模块, 一般用于功能更新等操作。
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 请求处理
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) 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 请求处理
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) Patch ¶ added in v0.32.0
func (r *Resource) Patch(h context.HandlerFunc) *Resource
Patch 指定个 PATCH 请求处理
type Server ¶ added in v0.32.0
type Server struct {
// contains filtered or unexported fields
}
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
Init 初始化模块
若指定了 tag 参数,则只初始化与该标签相关联的内容。
一旦初始化完成,则不再接受添加新模块,也不能再次进行初始化。 Server 和 Module 之中的大部分功能将失去操作意义,比如 Server.NewModule 虽然能添加新模块到 Server,但并不能真正初始化新的模块并挂载。
func (*Server) NewModule ¶ added in v0.32.0
NewModule 声明一个新的模块
name 模块名称,需要全局唯一; desc 模块的详细信息; deps 表示当前模块的依赖模块名称,可以是插件中的模块名称。
type Service ¶ added in v0.25.0
type Service struct {
Title string
// contains filtered or unexported fields
}
Service 服务模型
type ServiceFunc ¶ added in v0.25.0
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