Documentation
¶
Index ¶
- type Context
- func (c *Context) BindJSON(val any) error
- func (c *Context) FormValue(key string) StringValue
- func (c *Context) PathValue(key string) StringValue
- func (c *Context) QueryValue(key string) StringValue
- func (c *Context) Render(tplName string, data any) error
- func (c *Context) RespJSON(code int, val any) error
- func (c *Context) RespOK(val any) error
- type FileDownloader
- type FileUploader
- type GoTemplateEngine
- type HTTPServer
- type HTTPServerOption
- type HandleFunc
- type Middleware
- type Server
- type StaticResourceHandler
- type StaticResourceHandlerOption
- type StringValue
- type TemplateEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Req *http.Request
// Resp 原生的 ResponseWriter。当你直接使用 Resp 的时候,
// 那么相当于你绕开了 RespStatusCode 和 RespData。
// 响应数据直接被发送到前端,其它中间件将无法修改响应
// 其实我们也可以考虑将这个做成私有的
Resp http.ResponseWriter
// 缓存的响应部分
// 这部分数据会在最后刷新
RespStatusCode int
RespData []byte
PathParams map[string]string
// 命中的路由
MatchedRoute string
// 主要用于 session 存储
UserValues map[string]any
// contains filtered or unexported fields
}
func (*Context) FormValue ¶
func (c *Context) FormValue(key string) StringValue
func (*Context) PathValue ¶
func (c *Context) PathValue(key string) StringValue
func (*Context) QueryValue ¶
func (c *Context) QueryValue(key string) StringValue
type FileDownloader ¶
type FileDownloader struct {
Dir string
}
FileDownloader 直接操作了 http.ResponseWriter 所以在 Middleware 里面将不能使用 RespData 因为没有赋值
func (*FileDownloader) Handle ¶
func (fd *FileDownloader) Handle() HandleFunc
type FileUploader ¶
type FileUploader struct {
// FileField 对应于文件在表单中的字段名字
FileField string
// DstPathFunc 用于计算目标路径
DstPathFunc func(fh *multipart.FileHeader) string
}
func (*FileUploader) Handle ¶
func (f *FileUploader) Handle() HandleFunc
type GoTemplateEngine ¶
func (*GoTemplateEngine) LoadFromFs ¶
func (g *GoTemplateEngine) LoadFromFs(files ...string) error
func (*GoTemplateEngine) LoadFromGlob ¶
func (g *GoTemplateEngine) LoadFromGlob(pattern string) error
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer(opts ...HTTPServerOption) *HTTPServer
func (*HTTPServer) GET ¶
func (h *HTTPServer) GET(path string, handler HandleFunc)
func (*HTTPServer) POST ¶
func (h *HTTPServer) POST(path string, handler HandleFunc)
func (*HTTPServer) ServeHTTP ¶
func (h *HTTPServer) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP HTTPServer 处理请求的入口
func (*HTTPServer) Use ¶
func (h *HTTPServer) Use(mdls ...Middleware)
type HTTPServerOption ¶
type HTTPServerOption func(server *HTTPServer)
func ServerWithMiddleware ¶
func ServerWithMiddleware(mdls ...Middleware) HTTPServerOption
func ServerWithTemplateEngine ¶
func ServerWithTemplateEngine(tplEngine TemplateEngine) HTTPServerOption
type HandleFunc ¶
type HandleFunc func(ctx *Context)
type Middleware ¶
type Middleware func(next HandleFunc) HandleFunc
type StaticResourceHandler ¶
type StaticResourceHandler struct {
// contains filtered or unexported fields
}
func NewStaticResourceHandler ¶
func NewStaticResourceHandler(dir string, pathPrefix string, opts ...StaticResourceHandlerOption) *StaticResourceHandler
func (*StaticResourceHandler) Handle ¶
func (h *StaticResourceHandler) Handle(ctx *Context)
type StaticResourceHandlerOption ¶
type StaticResourceHandlerOption func(s *StaticResourceHandler)
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
func (StringValue) String ¶
func (s StringValue) String() (string, error)
Click to show internal directories.
Click to hide internal directories.
