module

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package module 提供模块的的相关功能。

Index

Constants

View Source
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 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) error

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) error

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, delay bool) error

AddTicker 添加新的定时任务

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

func (*Module) Delete

func (m *Module) Delete(path string, h http.Handler) *mux.Prefix

Delete 指定个 Delete 请求处理

func (*Module) DeleteFunc

func (m *Module) DeleteFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix

DeleteFunc 指定一个 Delete 请求

func (*Module) Get

func (m *Module) Get(path string, h http.Handler) *mux.Prefix

Get 指定一个 GET 请求

func (*Module) GetFunc

func (m *Module) GetFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix

GetFunc 指定一个 GET 请求

func (*Module) Handle

func (m *Module) Handle(path string, h http.Handler, methods ...string) error

Handle 添加一个路由项

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

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

NewTag 为当前模块生成特定名称的子模块。若已经存在,则直接返回该子模块。

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

func (*Module) Patch

func (m *Module) Patch(path string, h http.Handler) *mux.Prefix

Patch 指定个 Patch 请求处理

func (*Module) PatchFunc

func (m *Module) PatchFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix

PatchFunc 指定一个 Patch 请求

func (*Module) Plugin added in v0.25.0

func (m *Module) Plugin(name, description string, deps ...string)

Plugin 设置插件信息

在将模块设置为插件模式时,可以在插件的初始化函数中,采用此方法设置插件的基本信息。

func (*Module) Post

func (m *Module) Post(path string, h http.Handler) *mux.Prefix

Post 指定个 POST 请求处理

func (*Module) PostFunc

func (m *Module) PostFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix

PostFunc 指定一个 Post 请求

func (*Module) Prefix

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

Prefix 声明一个 Prefix 实例。

func (*Module) Put

func (m *Module) Put(path string, h http.Handler) *mux.Prefix

Put 指定个 Put 请求处理

func (*Module) PutFunc

func (m *Module) PutFunc(path string, h func(w http.ResponseWriter, r *http.Request)) *mux.Prefix

PutFunc 指定一个 Put 请求

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

func NewModules(conf *webconfig.WebConfig, logs *logs.Logs) (*Modules, error)

NewModules 声明 Modules 变量

func (*Modules) Init added in v0.25.0

func (ms *Modules) Init(tag string, log *log.Logger) error

Init 初始化所有的模块或是模块下指定标签名称的函数。

若指定了 tag 参数,则只初始化该名称的子模块内容。

指定 log 参数,可以输出详细的初始化步骤。

func (*Modules) Jobs added in v0.26.0

func (ms *Modules) Jobs() []*Job

Jobs 返回所有的计划任务

func (*Modules) Logs added in v0.26.0

func (ms *Modules) Logs() *logs.Logs

Logs 返回 logs.Logs 实例

func (*Modules) Modules added in v0.25.0

func (ms *Modules) Modules() []*Module

Modules 获取所有的模块信息

func (*Modules) Mux added in v0.25.0

func (ms *Modules) Mux() *mux.Mux

Mux 返回相关的 mux.Mux 实例

func (*Modules) NewModule added in v0.25.0

func (ms *Modules) NewModule(name, desc string, deps ...string) *Module

NewModule 声明一个新的模块

func (*Modules) Services added in v0.25.0

func (ms *Modules) Services() []*Service

Services 返回所有的服务列表

func (*Modules) Stop added in v0.25.0

func (ms *Modules) Stop()

Stop 停止服务

func (*Modules) Tags added in v0.25.0

func (ms *Modules) Tags() []string

Tags 返回所有的子模块名称

type Service added in v0.25.0

type Service struct {
	Title  string
	Module *Module
	// 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 (
	ServiceStop    ServiceState = iota // 当前处理停止状态,默认状态
	ServiceRunning                     // 正在运行
	ServiceFailed                      // 出错,不再执行后续操作
)

几种可能的状态值

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
JackTT - Gopher 🇻🇳