Documentation ¶
Index ¶
- func CheckForJSON(r *http.Request) error
- func FileHandler(w http.ResponseWriter, req *http.Request)
- func MatchesContentType(contentType, expectedType string) bool
- func NewPg(dbconfig DBConfig) *pg.DB
- func ParseForm(r *http.Request) error
- func ParseMultipartForm(r *http.Request) error
- func WriteError(w http.ResponseWriter, err error)
- func WriteJSON(w http.ResponseWriter, code int, v interface{}) error
- type CommonConfig
- type Config
- type Context
- type DBConfig
- type Error
- type ErrorType
- type FilterHanderFunc
- type HTTPAPIFunc
- type HandlerFunc
- type HandlersChain
- type Middleware
- type Param
- type Params
- type Route
- func NewDeleteRoute(path string, handler HTTPAPIFunc) Route
- func NewGetRoute(path string, handler HTTPAPIFunc) Route
- func NewHeadRoute(path string, handler HTTPAPIFunc) Route
- func NewOptionsRoute(path string, handler HTTPAPIFunc) Route
- func NewPostRoute(path string, handler HTTPAPIFunc) Route
- func NewPutRoute(path string, handler HTTPAPIFunc) Route
- func NewRoute(method, path string, handler HTTPAPIFunc) Route
- type Router
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckForJSON ¶
CheckForJSON makes sure that the request's Content-Type is application/json.
func MatchesContentType ¶
MatchesContentType validates the content type against the expected one
func ParseForm ¶
ParseForm ensures the request form is parsed even with invalid content types. If we don't do this, POST method without Content-type (even with empty body) will fail.
func ParseMultipartForm ¶
ParseMultipartForm ensure the request form is parsed, even with invalid content types.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError decodes a specific docker error and sends it in the response.
Types ¶
type CommonConfig ¶
type CommonConfig struct { Name string `json:"name"` Version string `json:"version"` Host string `json:"host"` Port int `json:"port"` Logging bool `json:"logging"` LogLevel log.Level `json:"log_level"` LogFile string `json:"log_file"` CookieSecret string `json:"cookie_secret"` Static []struct { URI string `json:"uri"` Filesystem string `json:"filesystem"` } `json:"static"` CertFile string `json:"cert_file"` KeyFile string `json:"key_file"` }
CommonConfig 基础配置信息
type Config ¶
type Config struct { CommonConfig Database DBConfig `json:"database"` }
Config 系统配置信息 Load Config : utils.ParseJSONFile(filename, &Config)
type Context ¶
type Context struct { Request *http.Request Writer http.ResponseWriter Params Params Errors errorMsgs Accepted []string // contains filtered or unexported fields }
Context 上下文信息
type DBConfig ¶
type DBConfig struct { Database string `json:"database"` Host string `json:"host"` Port string `json:"port"` User string `json:"user"` Password string `json:"password"` PoolSize int `json:"poolsize"` }
DBConfig 数据库配置
type FilterHanderFunc ¶
type FilterHanderFunc func(permission uint, handler HTTPAPIFunc) HTTPAPIFunc
FilterHanderFunc 权限过滤中间件
type HTTPAPIFunc ¶
type HTTPAPIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error
HTTPAPIFunc 函数类型
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Route ¶
type Route interface { Method() string Path() string Handler() HTTPAPIFunc }
Route 路由表
func NewDeleteRoute ¶
func NewDeleteRoute(path string, handler HTTPAPIFunc) Route
NewDeleteRoute initializes a new route with the http method DELETE.
func NewGetRoute ¶
func NewGetRoute(path string, handler HTTPAPIFunc) Route
NewGetRoute initializes a new route with the http method GET.
func NewHeadRoute ¶
func NewHeadRoute(path string, handler HTTPAPIFunc) Route
NewHeadRoute initializes a new route with the http method HEAD.
func NewOptionsRoute ¶
func NewOptionsRoute(path string, handler HTTPAPIFunc) Route
NewOptionsRoute initializes a new route with the http method OPTIONS
func NewPostRoute ¶
func NewPostRoute(path string, handler HTTPAPIFunc) Route
NewPostRoute initializes a new route with the http method POST.
func NewPutRoute ¶
func NewPutRoute(path string, handler HTTPAPIFunc) Route
NewPutRoute initializes a new route with the http method PUT.
func NewRoute ¶
func NewRoute(method, path string, handler HTTPAPIFunc) Route
NewRoute initializes a new local router for the reouter