Documentation
¶
Overview ¶
Package module 提供模块的的相关功能。
Index ¶
- Constants
- type Module
- func (m *Module) AddInit(f func() error, title string) *Module
- func (m *Module) AddService(f ServiceFunc, title string)
- 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) *Module
- 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) 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
Constants ¶
View Source
const ( // CoreModuleName 框架自带的模块名称 // // 该模块会在所有模块初始化之后,进行最后的初始化操作,包括了以下内容: // - 配置文件中指定的静态文件服务内容 static; // - 所有模块注册的服务,也有此模块负责启动。 CoreModuleName = "web-core" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Module ¶
type Module struct {
Name string
Description string
Deps []string
// contains filtered or unexported fields
}
Module 表示模块信息
func (*Module) AddService ¶ added in v0.25.0
func (m *Module) AddService(f ServiceFunc, title string)
AddService 添加新的服务
f 表示服务的运行函数; title 是对该服务的简要说明。
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 指定一个请求
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 + 1 // 当前处理停止状态,默认状态 ServiceRunning // 正在运行 ServiceFailed // 出错,不再执行后续操作 )
几种可能的状态值
Click to show internal directories.
Click to hide internal directories.