Documentation
¶
Overview ¶
Package web 一个微型的 RESTful API 框架
Index ¶
Constants ¶
View Source
const Version = "0.41.0"
Version 当前框架的版本
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶ added in v0.41.0
type Command struct {
Name string // 程序名称
Version string // 程序版本
RegisterModules func(*Server) error // 注册模块
// 当作服务运行的标签名
//
// 当标签名与此值相同时,在执行完 Server.InitModules 之后,还会执行 Server.Serve。
//
// 可以为空。
ServeTags []string
// 触发退出的信号
//
// 为空(nil 或是 []) 表示没有。
Signals []os.Signal
// 自定义命令行参数名
CmdVersion string // 默认为 v
CmdTag string // 默认为 tag
CmdFS string // 默认为 fs
// 命令行输出信息的通道
//
// 可以 os.Stdout 和 os.Stderr 选择,默认为 os.Stdout。
Out io.Writer
ResultBuilder content.BuildResultFunc // 默认为 nil,最终会被初始化 content.DefaultBuilder
Locale *serialization.Locale // 默认情况下,能正常解析 xml、yaml 和 json
LogsFilename string // 默认为 logs.xml
WebFilename string // 默认为 web.yaml
}
Command 提供一种简单的命令行处理方式
由 Command 生成的命令行带以下三个参数:
- tag 运行的标签;
- v 显示版本号;
- fs 指定当前程序可读取的文件目录;
以上三个参数的参数名称,可在配置内容中修改。
cmd := &web.Command{
Name: "app",
Version: "1.0.0",
ServeTags: []string{"serve"},
RegisterModules: func(s *Server) error {...}
}
cmd.Exec()
type Context ¶
func NewContext ¶
func NewContext(w http.ResponseWriter, r *http.Request) *Context
NewContext 构建 *Context 实例
type HandlerFunc ¶ added in v0.33.0
type HandlerFunc = server.HandlerFunc
type Locale ¶ added in v0.41.0
type Locale = serialization.Locale
type Server ¶ added in v0.25.0
func LoadServer ¶ added in v0.39.0
func LoadServer(name, version string, build content.BuildResultFunc, l *Locale, f fs.FS, logs, web string) (*Server, error)
LoadServer 从配置文件加载并实例化 Server 对象
locale 指定了用于加载本地化的方法,同时其关联的 serialization.Files 也用于加载配置文件; logs 和 web 用于指定日志和项目的配置文件,根据扩展由 serialization.Files 负责在 f 查找文件加载;
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
web
module
|
|
|
Package config 提供了从配置文件初始化 server.Options 的方法
|
Package config 提供了从配置文件初始化 server.Options 的方法 |
|
Package content 与生成内容相关的功能
|
Package content 与生成内容相关的功能 |
|
form
Package form 用于处理 www-form-urlencoded 编码 func read(ctx *web.Context) { vals := urls.Values{} ctx.Read(vals) } func write(ctx *web.Context) { vals := urls.Values{} vals.Add("name", "caixw") ctx.Render(http.StatusOK, vals, nil) } form 用户可以通过定义 form 标签自定义输出的名称,比如: type Username struct { Name string `form:"name"` Age int } 转换成 form-data 可能是以下样式: name=jjj&age=18 该方式对数据类型有一定限制: 1.
|
Package form 用于处理 www-form-urlencoded 编码 func read(ctx *web.Context) { vals := urls.Values{} ctx.Read(vals) } func write(ctx *web.Context) { vals := urls.Values{} vals.Add("name", "caixw") ctx.Render(http.StatusOK, vals, nil) } form 用户可以通过定义 form 标签自定义输出的名称,比如: type Username struct { Name string `form:"name"` Age int } 转换成 form-data 可能是以下样式: name=jjj&age=18 该方式对数据类型有一定限制: 1. |
|
gob
Package gob 提供 GOB 格式的编解码
|
Package gob 提供 GOB 格式的编解码 |
|
html
Package html 提供输出 HTML 内容的 content.MarshalFunc 函数 mt := content.NewContent() tpl := template.ParseFiles(...) mgr := html.New(tpl) mt.Add("text/html", mgr.Marshal, nil) func handle(ctx *web.Context) Responser { return Object(200, html.Tpl("index", map[string]interface{}{...}), nil) }
|
Package html 提供输出 HTML 内容的 content.MarshalFunc 函数 mt := content.NewContent() tpl := template.ParseFiles(...) mgr := html.New(tpl) mt.Add("text/html", mgr.Marshal, nil) func handle(ctx *web.Context) Responser { return Object(200, html.Tpl("index", map[string]interface{}{...}), nil) } |
|
text
Package text 针对文本内容的编解码实现
|
Package text 针对文本内容的编解码实现 |
|
text/testobject
Package testobject 用于测试 mimetype 的对象
|
Package testobject 用于测试 mimetype 的对象 |
|
internal
|
|
|
charsetdata
Package charsetdata 用于测试的字符集数据
|
Package charsetdata 用于测试的字符集数据 |
|
filesystem
Package filesystem 提供文件系统的相关操作
|
Package filesystem 提供文件系统的相关操作 |
|
plugintest
Package plugintest 作为插件的功能测试包 NOTE: 该测试如果直接写在功能所在的包,目前版本会报错。
|
Package plugintest 作为插件的功能测试包 NOTE: 该测试如果直接写在功能所在的包,目前版本会报错。 |
|
Package serialization 序列化相关的操作
|
Package serialization 序列化相关的操作 |
|
Package server web 服务管理
|
Package server web 服务管理 |
|
Package service 服务管理
|
Package service 服务管理 |
Click to show internal directories.
Click to hide internal directories.