forked from mirror/gin
separate type define (#975)
This commit is contained in:
parent
22fc0284e3
commit
d535fcd598
18
auth.go
18
auth.go
|
@ -13,15 +13,15 @@ import (
|
||||||
// AuthUserKey is the cookie name for user credential in basic auth
|
// AuthUserKey is the cookie name for user credential in basic auth
|
||||||
const AuthUserKey = "user"
|
const AuthUserKey = "user"
|
||||||
|
|
||||||
type (
|
// Accounts defines a key/value for user/pass list of authorized logins
|
||||||
// Accounts defines a key/value for user/pass list of authorized logins
|
type Accounts map[string]string
|
||||||
Accounts map[string]string
|
|
||||||
authPair struct {
|
type authPair struct {
|
||||||
Value string
|
Value string
|
||||||
User string
|
User string
|
||||||
}
|
}
|
||||||
authPairs []authPair
|
|
||||||
)
|
type authPairs []authPair
|
||||||
|
|
||||||
func (a authPairs) searchCredential(authValue string) (string, bool) {
|
func (a authPairs) searchCredential(authValue string) (string, bool) {
|
||||||
if len(authValue) == 0 {
|
if len(authValue) == 0 {
|
||||||
|
|
14
errors.go
14
errors.go
|
@ -23,15 +23,13 @@ const (
|
||||||
ErrorTypeNu = 2
|
ErrorTypeNu = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type Error struct {
|
||||||
Error struct {
|
Err error
|
||||||
Err error
|
Type ErrorType
|
||||||
Type ErrorType
|
Meta interface{}
|
||||||
Meta interface{}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
errorMsgs []*Error
|
type errorMsgs []*Error
|
||||||
)
|
|
||||||
|
|
||||||
var _ error = &Error{}
|
var _ error = &Error{}
|
||||||
|
|
||||||
|
|
15
fs.go
15
fs.go
|
@ -9,14 +9,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type onlyfilesFS struct {
|
||||||
onlyfilesFS struct {
|
fs http.FileSystem
|
||||||
fs http.FileSystem
|
}
|
||||||
}
|
|
||||||
neuteredReaddirFile struct {
|
type neuteredReaddirFile struct {
|
||||||
http.File
|
http.File
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
|
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
|
||||||
// in router.Static().
|
// in router.Static().
|
||||||
|
|
109
gin.go
109
gin.go
|
@ -33,67 +33,66 @@ func (c HandlersChain) Last() HandlerFunc {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type RouteInfo struct {
|
||||||
RoutesInfo []RouteInfo
|
Method string
|
||||||
RouteInfo struct {
|
Path string
|
||||||
Method string
|
Handler string
|
||||||
Path string
|
}
|
||||||
Handler string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
|
type RoutesInfo []RouteInfo
|
||||||
// Create an instance of Engine, by using New() or Default()
|
|
||||||
Engine struct {
|
|
||||||
RouterGroup
|
|
||||||
delims render.Delims
|
|
||||||
HTMLRender render.HTMLRender
|
|
||||||
FuncMap template.FuncMap
|
|
||||||
allNoRoute HandlersChain
|
|
||||||
allNoMethod HandlersChain
|
|
||||||
noRoute HandlersChain
|
|
||||||
noMethod HandlersChain
|
|
||||||
pool sync.Pool
|
|
||||||
trees methodTrees
|
|
||||||
|
|
||||||
// Enables automatic redirection if the current route can't be matched but a
|
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
|
||||||
// handler for the path with (without) the trailing slash exists.
|
// Create an instance of Engine, by using New() or Default()
|
||||||
// For example if /foo/ is requested but a route only exists for /foo, the
|
type Engine struct {
|
||||||
// client is redirected to /foo with http status code 301 for GET requests
|
RouterGroup
|
||||||
// and 307 for all other request methods.
|
delims render.Delims
|
||||||
RedirectTrailingSlash bool
|
HTMLRender render.HTMLRender
|
||||||
|
FuncMap template.FuncMap
|
||||||
|
allNoRoute HandlersChain
|
||||||
|
allNoMethod HandlersChain
|
||||||
|
noRoute HandlersChain
|
||||||
|
noMethod HandlersChain
|
||||||
|
pool sync.Pool
|
||||||
|
trees methodTrees
|
||||||
|
|
||||||
// If enabled, the router tries to fix the current request path, if no
|
// Enables automatic redirection if the current route can't be matched but a
|
||||||
// handle is registered for it.
|
// handler for the path with (without) the trailing slash exists.
|
||||||
// First superfluous path elements like ../ or // are removed.
|
// For example if /foo/ is requested but a route only exists for /foo, the
|
||||||
// Afterwards the router does a case-insensitive lookup of the cleaned path.
|
// client is redirected to /foo with http status code 301 for GET requests
|
||||||
// If a handle can be found for this route, the router makes a redirection
|
// and 307 for all other request methods.
|
||||||
// to the corrected path with status code 301 for GET requests and 307 for
|
RedirectTrailingSlash bool
|
||||||
// all other request methods.
|
|
||||||
// For example /FOO and /..//Foo could be redirected to /foo.
|
|
||||||
// RedirectTrailingSlash is independent of this option.
|
|
||||||
RedirectFixedPath bool
|
|
||||||
|
|
||||||
// If enabled, the router checks if another method is allowed for the
|
// If enabled, the router tries to fix the current request path, if no
|
||||||
// current route, if the current request can not be routed.
|
// handle is registered for it.
|
||||||
// If this is the case, the request is answered with 'Method Not Allowed'
|
// First superfluous path elements like ../ or // are removed.
|
||||||
// and HTTP status code 405.
|
// Afterwards the router does a case-insensitive lookup of the cleaned path.
|
||||||
// If no other Method is allowed, the request is delegated to the NotFound
|
// If a handle can be found for this route, the router makes a redirection
|
||||||
// handler.
|
// to the corrected path with status code 301 for GET requests and 307 for
|
||||||
HandleMethodNotAllowed bool
|
// all other request methods.
|
||||||
ForwardedByClientIP bool
|
// For example /FOO and /..//Foo could be redirected to /foo.
|
||||||
|
// RedirectTrailingSlash is independent of this option.
|
||||||
|
RedirectFixedPath bool
|
||||||
|
|
||||||
// #726 #755 If enabled, it will thrust some headers starting with
|
// If enabled, the router checks if another method is allowed for the
|
||||||
// 'X-AppEngine...' for better integration with that PaaS.
|
// current route, if the current request can not be routed.
|
||||||
AppEngine bool
|
// If this is the case, the request is answered with 'Method Not Allowed'
|
||||||
|
// and HTTP status code 405.
|
||||||
|
// If no other Method is allowed, the request is delegated to the NotFound
|
||||||
|
// handler.
|
||||||
|
HandleMethodNotAllowed bool
|
||||||
|
ForwardedByClientIP bool
|
||||||
|
|
||||||
// If enabled, the url.RawPath will be used to find parameters.
|
// #726 #755 If enabled, it will thrust some headers starting with
|
||||||
UseRawPath bool
|
// 'X-AppEngine...' for better integration with that PaaS.
|
||||||
// If true, the path value will be unescaped.
|
AppEngine bool
|
||||||
// If UseRawPath is false (by default), the UnescapePathValues effectively is true,
|
|
||||||
// as url.Path gonna be used, which is already unescaped.
|
// If enabled, the url.RawPath will be used to find parameters.
|
||||||
UnescapePathValues bool
|
UseRawPath bool
|
||||||
}
|
// If true, the path value will be unescaped.
|
||||||
)
|
// If UseRawPath is false (by default), the UnescapePathValues effectively is true,
|
||||||
|
// as url.Path gonna be used, which is already unescaped.
|
||||||
|
UnescapePathValues bool
|
||||||
|
}
|
||||||
|
|
||||||
var _ IRouter = &Engine{}
|
var _ IRouter = &Engine{}
|
||||||
|
|
||||||
|
|
|
@ -16,36 +16,34 @@ const (
|
||||||
defaultStatus = 200
|
defaultStatus = 200
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type ResponseWriter interface {
|
||||||
ResponseWriter interface {
|
http.ResponseWriter
|
||||||
http.ResponseWriter
|
http.Hijacker
|
||||||
http.Hijacker
|
http.Flusher
|
||||||
http.Flusher
|
http.CloseNotifier
|
||||||
http.CloseNotifier
|
|
||||||
|
|
||||||
// Returns the HTTP response status code of the current request.
|
// Returns the HTTP response status code of the current request.
|
||||||
Status() int
|
Status() int
|
||||||
|
|
||||||
// Returns the number of bytes already written into the response http body.
|
// Returns the number of bytes already written into the response http body.
|
||||||
// See Written()
|
// See Written()
|
||||||
Size() int
|
Size() int
|
||||||
|
|
||||||
// Writes the string into the response body.
|
// Writes the string into the response body.
|
||||||
WriteString(string) (int, error)
|
WriteString(string) (int, error)
|
||||||
|
|
||||||
// Returns true if the response body was already written.
|
// Returns true if the response body was already written.
|
||||||
Written() bool
|
Written() bool
|
||||||
|
|
||||||
// Forces to write the http header (status code + headers).
|
// Forces to write the http header (status code + headers).
|
||||||
WriteHeaderNow()
|
WriteHeaderNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
responseWriter struct {
|
type responseWriter struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
size int
|
size int
|
||||||
status int
|
status int
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
var _ ResponseWriter = &responseWriter{}
|
var _ ResponseWriter = &responseWriter{}
|
||||||
|
|
||||||
|
|
|
@ -11,39 +11,37 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type IRouter interface {
|
||||||
IRouter interface {
|
IRoutes
|
||||||
IRoutes
|
Group(string, ...HandlerFunc) *RouterGroup
|
||||||
Group(string, ...HandlerFunc) *RouterGroup
|
}
|
||||||
}
|
|
||||||
|
|
||||||
IRoutes interface {
|
type IRoutes interface {
|
||||||
Use(...HandlerFunc) IRoutes
|
Use(...HandlerFunc) IRoutes
|
||||||
|
|
||||||
Handle(string, string, ...HandlerFunc) IRoutes
|
Handle(string, string, ...HandlerFunc) IRoutes
|
||||||
Any(string, ...HandlerFunc) IRoutes
|
Any(string, ...HandlerFunc) IRoutes
|
||||||
GET(string, ...HandlerFunc) IRoutes
|
GET(string, ...HandlerFunc) IRoutes
|
||||||
POST(string, ...HandlerFunc) IRoutes
|
POST(string, ...HandlerFunc) IRoutes
|
||||||
DELETE(string, ...HandlerFunc) IRoutes
|
DELETE(string, ...HandlerFunc) IRoutes
|
||||||
PATCH(string, ...HandlerFunc) IRoutes
|
PATCH(string, ...HandlerFunc) IRoutes
|
||||||
PUT(string, ...HandlerFunc) IRoutes
|
PUT(string, ...HandlerFunc) IRoutes
|
||||||
OPTIONS(string, ...HandlerFunc) IRoutes
|
OPTIONS(string, ...HandlerFunc) IRoutes
|
||||||
HEAD(string, ...HandlerFunc) IRoutes
|
HEAD(string, ...HandlerFunc) IRoutes
|
||||||
|
|
||||||
StaticFile(string, string) IRoutes
|
StaticFile(string, string) IRoutes
|
||||||
Static(string, string) IRoutes
|
Static(string, string) IRoutes
|
||||||
StaticFS(string, http.FileSystem) IRoutes
|
StaticFS(string, http.FileSystem) IRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
|
// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
|
||||||
// and an array of handlers (middleware)
|
// and an array of handlers (middleware)
|
||||||
RouterGroup struct {
|
type RouterGroup struct {
|
||||||
Handlers HandlersChain
|
Handlers HandlersChain
|
||||||
basePath string
|
basePath string
|
||||||
engine *Engine
|
engine *Engine
|
||||||
root bool
|
root bool
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
var _ IRouter = &RouterGroup{}
|
var _ IRouter = &RouterGroup{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue