Documentation
¶
Overview ¶
Package module 提供模块的的相关功能。
Index ¶
- Constants
- type Job
- type JobFunc
- type Module
- func (m *Module) AddAt(title string, f JobFunc, spec string, delay bool) error
- func (m *Module) AddCron(title string, f JobFunc, spec string, delay bool) error
- func (m *Module) AddService(f ServiceFunc, title string)
- func (m *Module) AddTicker(title string, f JobFunc, dur time.Duration, delay bool) error
- func (m *Module) Delete(path string, h http.Handler) *mux.Prefix
- func (m *Module) DeleteFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
- func (m *Module) Get(path string, h http.Handler) *mux.Prefix
- func (m *Module) GetFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
- func (m *Module) Handle(path string, h http.Handler, methods ...string) error
- func (m *Module) HandleFunc(path string, h func(w http.ResponseWriter, r *http.Request), methods ...string) error
- func (m *Module) NewTag(tag string) *Tag
- func (m *Module) Patch(path string, h http.Handler) *mux.Prefix
- func (m *Module) PatchFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
- func (m *Module) Plugin(name, description string, deps ...string)
- func (m *Module) Post(path string, h http.Handler) *mux.Prefix
- func (m *Module) PostFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
- func (m *Module) Prefix(prefix string) *mux.Prefix
- func (m *Module) Put(path string, h http.Handler) *mux.Prefix
- func (m *Module) PutFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
- type Modules
- func (ms *Modules) Init(tag string, log *log.Logger) error
- func (ms *Modules) Jobs() []*Job
- func (ms *Modules) Logs() *logs.Logs
- func (ms *Modules) Modules() []*Module
- func (ms *Modules) Mux() *mux.Mux
- func (ms *Modules) NewModule(name, desc string, deps ...string) *Module
- func (ms *Modules) Services() []*Service
- func (ms *Modules) Stop()
- func (ms *Modules) Tags() []string
- type Service
- type ServiceFunc
- type ServiceState
- type Tag
Constants ¶
const ( // CoreModuleName 框架自带的模块名称 // // 该模块会在所有模块初始化之后,进行最后的初始化操作,包括了以下内容: // - 配置文件中指定的静态文件服务内容 static; // - 所有模块注册的服务,也由此模块负责启动。 CoreModuleName = "web-core" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶ added in v0.26.0
type Job struct { State scheduled.State Title string Prev time.Time Next time.Time Scheduled string }
Job 描述计划任务的信息。
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 是对该服务的简要说明; delay 是否在任务执行完之后,才计算下一次的执行时间点。
func (*Module) DeleteFunc ¶
func (m *Module) DeleteFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix
DeleteFunc 指定一个 Delete 请求
func (*Module) HandleFunc ¶
func (m *Module) HandleFunc(path string, h func(w http.ResponseWriter, r *http.Request), methods ...string) error
HandleFunc 指定一个请求
func (*Module) NewTag ¶ added in v0.16.1
NewTag 为当前模块生成特定名称的子模块。若已经存在,则直接返回该子模块。
Tag 是依赖关系与当前模块相同,但是功能完全独立的模块, 一般用于功能更新等操作。
type Modules ¶ added in v0.25.0
type Modules struct { middleware.Manager // contains filtered or unexported fields }
Modules 模块管理
负责模块的初始化工作,包括路由的加载等。
func NewModules ¶ added in v0.25.0
NewModules 声明 Modules 变量
func (*Modules) Init ¶ added in v0.25.0
Init 初始化所有的模块或是模块下指定标签名称的函数。
若指定了 tag 参数,则只初始化该名称的子模块内容。
指定 log 参数,可以输出详细的初始化步骤。
type ServiceFunc ¶ added in v0.25.0
ServiceFunc 服务实际需要执行的函数
实现者需要正确处理 ctx.Done 事件,调用者可能会主动取消函数执行; 如果是通 ctx 取消的,应该返回其错误信息。
type ServiceState ¶ added in v0.25.0
type ServiceState int8
ServiceState 服务的状态值
const ( ServiceStop ServiceState = iota // 当前处理停止状态,默认状态 ServiceRunning // 正在运行 ServiceFailed // 出错,不再执行后续操作 )
几种可能的状态值