module

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// CoreModuleName 模块名称
	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) AddInit

func (m *Module) AddInit(f func() error, title string) *Module

AddInit 添加一个初始化函数

title 该初始化函数的名称。没有则会自动生成一个序号,多个,则取第一个元素。

func (*Module) AddService added in v0.25.0

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

AddService 添加新的服务

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) *Module

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

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) *Module

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) (*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) 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 + 1 // 当前处理停止状态,默认状态
	ServiceRunning                         // 正在运行
	ServiceFailed                          // 出错,不再执行后续操作
)

几种可能的状态值

Jump to

Keyboard shortcuts

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