module

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMessage deprecated

func NewMessage(msg string) error

NewMessage 声明一条 message 类型的错误信息

返回内容并不是一个真正的错误,则是在某些时候需要在安装完成之后, 反馈一些文字信息,则需要用此函数进行包装。

Deprecated: 采用 NewTag 代替

Types

type Init added in v0.16.1

type Init struct {
	Title string
	F     func() error
}

Init 表示初始化功能的相关数据

type Module

type Module struct {
	Type        Type
	Name        string
	Deps        []string
	Description string

	// 第一个键名为路径,第二键名为请求方法
	Routes map[string]map[string]http.Handler

	// 一些初始化函数
	Inits []*Init

	// 保存特定标签下的子模块。
	Tags map[string]*Module
}

Module 表示模块信息

func New

func New(typ Type, name, desc string, deps ...string) *Module

New 声明一个新的模块

name 模块名称,需要全局唯一; desc 模块的详细信息; deps 表示当前模块的依赖模块名称,可以是插件中的模块名称。

仅供框架内部使用,不保证函数签名的兼容性。

func (*Module) AddInit

func (m *Module) AddInit(f func() error) *Module

AddInit 添加一个初始化函数

func (*Module) AddInitTitle added in v0.16.1

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

AddInitTitle 添加一个初始化函数,带描述信息。

func (*Module) Delete

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

Delete 指定个 Delete 请求处理

func (*Module) DeleteFunc

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

DeleteFunc 指定一个 Delete 请求

func (*Module) Get

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

Get 指定一个 GET 请求

func (*Module) GetFunc

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

GetFunc 指定一个 GET 请求

func (*Module) Handle

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

Handle 添加一个路由项

func (*Module) HandleFunc

func (m *Module) HandleFunc(path string, h func(w http.ResponseWriter, r *http.Request), methods ...string) *Module

HandleFunc 指定一个请求

func (*Module) NewTag added in v0.16.1

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

NewTag 为当前模块生成特定名称的子模块。

func (*Module) NewVersion deprecated

func (m *Module) NewVersion(version string) *Module

NewVersion 为当前模块添加某一版本号下的安装脚本。

Deprecated: 采用 NewTag 代替

func (*Module) Patch

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

Patch 指定个 Patch 请求处理

func (*Module) PatchFunc

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

PatchFunc 指定一个 Patch 请求

func (*Module) Post

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

Post 指定个 POST 请求处理

func (*Module) PostFunc

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

PostFunc 指定一个 Post 请求

func (*Module) Prefix

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

Prefix 声明一个 Prefix 实例。

func (*Module) Put

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

Put 指定个 Put 请求处理

func (*Module) PutFunc

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

PutFunc 指定一个 Put 请求

func (*Module) Task deprecated

func (m *Module) Task(title string, fn func() error)

Task 添加一条安装脚本

Deprecated: 仅作为兼容保存,下个版本删除

type Prefix

type Prefix struct {
	// contains filtered or unexported fields
}

Prefix 可以将具有统一前缀的路由项集中在一起操作。

p := srv.Prefix("/api")
p.Get("/users")  // 相当于 srv.Get("/api/users")
p.Get("/user/1") // 相当于 srv.Get("/api/user/1")

func (*Prefix) Delete

func (p *Prefix) Delete(path string, h http.Handler) *Prefix

Delete 指定一个 Delete 请求

func (*Prefix) DeleteFunc

func (p *Prefix) DeleteFunc(path string, f http.HandlerFunc) *Prefix

DeleteFunc 指定一个 Delete 请求

func (*Prefix) Get

func (p *Prefix) Get(path string, h http.Handler) *Prefix

Get 指定一个 GET 请求

func (*Prefix) GetFunc

func (p *Prefix) GetFunc(path string, f http.HandlerFunc) *Prefix

GetFunc 指定一个 Get 请求

func (*Prefix) Handle

func (p *Prefix) Handle(path string, h http.Handler, methods ...string) *Prefix

Handle 添加路由项

func (*Prefix) HandleFunc

func (p *Prefix) HandleFunc(path string, f http.HandlerFunc, methods ...string) *Prefix

HandleFunc 指定一个请求

func (*Prefix) Module

func (p *Prefix) Module() *Module

Module 返回关联的 Module 实全

func (*Prefix) Patch

func (p *Prefix) Patch(pattern string, h http.Handler) *Prefix

Patch 指定一个 Patch 请求

func (*Prefix) PatchFunc

func (p *Prefix) PatchFunc(path string, f http.HandlerFunc) *Prefix

PatchFunc 指定一个 Patch 请求

func (*Prefix) Post

func (p *Prefix) Post(path string, h http.Handler) *Prefix

Post 指定一个 Post 请求

func (*Prefix) PostFunc

func (p *Prefix) PostFunc(path string, f http.HandlerFunc) *Prefix

PostFunc 指定一个 Post 请求

func (*Prefix) Put

func (p *Prefix) Put(pattern string, h http.Handler) *Prefix

Put 指定一个 Put 请求

func (*Prefix) PutFunc

func (p *Prefix) PutFunc(path string, f http.HandlerFunc) *Prefix

PutFunc 指定一个 Put 请求

type Type

type Type int8

Type 表示模块的类型

const (
	TypeModule Type = iota + 1
	TypePlugin
	TypeTag
)

表示模块的类型

type Version deprecated

type Version = Module

Version 指定标签的模块

Deprecated: 仅作为兼容保存,下个版本删除

Jump to

Keyboard shortcuts

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