Documentation
¶
Index ¶
- func GetFileMapping() map[string][]byte
- func LastSlice(str string, maxLen int, prefix string) string
- type Brick
- func (b *Brick) GetCachedTemplate(fileName string) (*CachedTemplate, error)
- func (b *Brick) HttpJumpMapping(location string, to string)
- func (b *Brick) Service(path string, h HttpHandler)
- func (b *Brick) SetErrorHandler(p HttpErrorHandler)
- func (b *Brick) SetLogger(log Logger)
- func (b *Brick) SetTemplateDir(path string)
- func (b *Brick) StartHttpServer() error
- func (b *Brick) StaticPage(baseURL string, fileDir string)
- func (b *Brick) TemplatePage(templateFile string, handle TemplateHandler) HttpHandler
- type CachedTemplate
- type Http
- func (h *Http) CacheTime(d time.Duration)
- func (h *Http) CloseOnEnd(c Shutdown)
- func (h *Http) Ctx() context.Context
- func (h *Http) Get(name string) string
- func (h *Http) GetAcceptLanguage() string
- func (h *Http) GetTpl(filename string) (*template.Template, error)
- func (h *Http) Gets(name string) []string
- func (h *Http) Json(m interface{})
- func (h *Http) Session() *sessions.Session
- func (h *Http) Tag(tagName string, body func(), attr ...string)
- func (h *Http) TextTag(tagName string, text string, attr ...string)
- func (h *Http) URLParam(fixBase string, out ...*string) int
- func (h *Http) WriteCSS(href string)
- func (h *Http) WriteErr(e error)
- func (h *Http) WriteStr(s string)
- type HttpErrorHandler
- type HttpHandler
- type Logger
- type Msg
- type Shutdown
- type StaticPage
- type TemplateHandler
- type TplFuncCtx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFileMapping ¶
Types ¶
type Brick ¶
方便编写 http 服务
func (*Brick) GetCachedTemplate ¶
func (b *Brick) GetCachedTemplate(fileName string) (*CachedTemplate, error)
编译并返回 html 模板对象, 如果模板文件有变更, 会重新编译 TODO: 支持模板之间的 define/template 调用
func (*Brick) HttpJumpMapping ¶
把对 location 的请求跳转到 to 上, 如果参数 location == '/', 则对没有注册过的路径的请求都会转发到 to 上.
func (*Brick) SetErrorHandler ¶
func (b *Brick) SetErrorHandler(p HttpErrorHandler)
func (*Brick) StaticPage ¶
设置静态文件服务, 必须在该方法之前设置 log 否则无效
func (*Brick) TemplatePage ¶
func (b *Brick) TemplatePage( templateFile string, handle TemplateHandler) HttpHandler
创建模板服务 handle 返回的上下文对象中的数据绑定到 template_file 指定的模板中, 服务映射到 url 路径上. 如果使 HTTP HEAD 请求, 模板不会渲染, 如果没有错误则返回 204
type CachedTemplate ¶
type CachedTemplate struct {
// contains filtered or unexported fields
}
已经缓存的模板对象
type Http ¶
type Http struct {
R *http.Request
W http.ResponseWriter
// 在记录 http 日志时的附加条目
L string
// contains filtered or unexported fields
}
type HttpErrorHandler ¶
type HttpErrorHandler func(hd *Http, err interface{})
当发生 http 异常或 HttpHandler 返回错误, 对错误执行这个方法 通常记录日志并向客户端输出错误信息
type HttpHandler ¶
http 服务处理函数, 在可能返回 error 之前不要写出任何数据 返回的 error 会设置输出为 500 http code
type Logger ¶
type Logger interface {
Debug(v ...interface{})
Info(v ...interface{})
Warn(v ...interface{})
Error(v ...interface{})
Fmt(format string, v ...interface{})
}
type StaticPage ¶
type StaticPage struct {
BaseUrl string // web 服务的路径前缀
FilePath string // 本地文件路径
// contains filtered or unexported fields
}
func (*StaticPage) ServeHTTP ¶
func (p *StaticPage) ServeHTTP(w http.ResponseWriter, r *http.Request)
type TemplateHandler ¶
html 模板处理函数, 该函数准备渲染模板需要的数据, 并在第一个参数返回 如果出错, 返回第二个参数, 此时错误会输出到客户端, 并终止模板渲染 HEAD 请求不会渲染模板.
type TplFuncCtx ¶
type TplFuncCtx struct {
io.Writer
Data *interface{}
Dirname string
// contains filtered or unexported fields
}
HTML 模板上下文, 即模板中 '.' 符号表示的实例, '.Data' 是 TemplateHandler 函数返回的数据.
Click to show internal directories.
Click to hide internal directories.