Skip to content
Myr

separate type define (#975)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by 田欧 · committed by Bo-Yi Wu · parent 22fc028 · Browse files · 6 files+125 added−133 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+125 added−133 removed

  • other:+125 added−133 removed

6 files+125 added−133 removed

modified:auth.go+9 added-9 removed
11 unmodified lines
1213// AuthUserKey is the cookie name for user credential in basic auth14const AuthUserKey = "user"1516type (17 // Accounts defines a key/value for user/pass list of authorized logins18 Accounts map[string]string16// Accounts defines a key/value for user/pass list of authorized logins17type Accounts map[string]string19 authPair struct {20 Value string21 User string22 }23 authPairs []authPair24)1819type authPair struct {20 Value string21 User string22}2324type authPairs []authPair2526func (a authPairs) searchCredential(authValue string) (string, bool) {27 if len(authValue) == 0 {28 return "", false29 }
65 unmodified lines
modified:errors.go+6 added-8 removed
21 unmodified lines
22 ErrorTypeAny ErrorType = 1<<64 - 123 ErrorTypeNu = 224)2526type (27 Error struct {28 Err error29 Type ErrorType30 Meta interface{}31 }26type Error struct {27 Err error28 Type ErrorType29 Meta interface{}30}3133 errorMsgs []*Error34)32type errorMsgs []*Error3334var _ error = &Error{}3536func (msg *Error) SetType(flags ErrorType) *Error {
121 unmodified lines
modified:fs.go+7 added-8 removed
7 unmodified lines
8 "net/http"9 "os"10)1112type (13 onlyfilesFS struct {14 fs http.FileSystem15 }12type onlyfilesFS struct {13 fs http.FileSystem14}16 neuteredReaddirFile struct {17 http.File18 }19)1516type neuteredReaddirFile struct {17 http.File18}1920// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally21// in router.Static().22// if listDirectory == true, then it works the same as http.Dir() otherwise it returns23// a filesystem that prevents http.FileServer() to list the directory files.
22 unmodified lines
modified:gin.go+54 added-55 removed
31 unmodified lines
32 }33 return nil34}3536type (37 RoutesInfo []RouteInfo38 RouteInfo struct {39 Method string40 Path string41 Handler string42 }36type RouteInfo struct {37 Method string38 Path string39 Handler string40}4144 // Engine is the framework's instance, it contains the muxer, middleware and configuration settings.45 // Create an instance of Engine, by using New() or Default()46 Engine struct {47 RouterGroup48 delims render.Delims49 HTMLRender render.HTMLRender50 FuncMap template.FuncMap51 allNoRoute HandlersChain52 allNoMethod HandlersChain53 noRoute HandlersChain54 noMethod HandlersChain55 pool sync.Pool56 trees methodTrees42type RoutesInfo []RouteInfo4358 // Enables automatic redirection if the current route can't be matched but a59 // handler for the path with (without) the trailing slash exists.60 // For example if /foo/ is requested but a route only exists for /foo, the61 // client is redirected to /foo with http status code 301 for GET requests62 // and 307 for all other request methods.63 RedirectTrailingSlash bool44// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.45// Create an instance of Engine, by using New() or Default()46type Engine struct {47 RouterGroup48 delims render.Delims49 HTMLRender render.HTMLRender50 FuncMap template.FuncMap51 allNoRoute HandlersChain52 allNoMethod HandlersChain53 noRoute HandlersChain54 noMethod HandlersChain55 pool sync.Pool56 trees methodTrees5765 // If enabled, the router tries to fix the current request path, if no66 // handle is registered for it.67 // First superfluous path elements like ../ or // are removed.68 // Afterwards the router does a case-insensitive lookup of the cleaned path.69 // If a handle can be found for this route, the router makes a redirection70 // to the corrected path with status code 301 for GET requests and 307 for71 // all other request methods.72 // For example /FOO and /..//Foo could be redirected to /foo.73 // RedirectTrailingSlash is independent of this option.74 RedirectFixedPath bool58 // Enables automatic redirection if the current route can't be matched but a59 // handler for the path with (without) the trailing slash exists.60 // For example if /foo/ is requested but a route only exists for /foo, the61 // client is redirected to /foo with http status code 301 for GET requests62 // and 307 for all other request methods.63 RedirectTrailingSlash bool6476 // If enabled, the router checks if another method is allowed for the77 // current route, if the current request can not be routed.78 // If this is the case, the request is answered with 'Method Not Allowed'79 // and HTTP status code 405.80 // If no other Method is allowed, the request is delegated to the NotFound81 // handler.82 HandleMethodNotAllowed bool83 ForwardedByClientIP bool65 // If enabled, the router tries to fix the current request path, if no66 // handle is registered for it.67 // First superfluous path elements like ../ or // are removed.68 // Afterwards the router does a case-insensitive lookup of the cleaned path.69 // If a handle can be found for this route, the router makes a redirection70 // to the corrected path with status code 301 for GET requests and 307 for71 // all other request methods.72 // For example /FOO and /..//Foo could be redirected to /foo.73 // RedirectTrailingSlash is independent of this option.74 RedirectFixedPath bool7585 // #726 #755 If enabled, it will thrust some headers starting with86 // 'X-AppEngine...' for better integration with that PaaS.87 AppEngine bool76 // If enabled, the router checks if another method is allowed for the77 // current route, if the current request can not be routed.78 // If this is the case, the request is answered with 'Method Not Allowed'79 // and HTTP status code 405.80 // If no other Method is allowed, the request is delegated to the NotFound81 // handler.82 HandleMethodNotAllowed bool83 ForwardedByClientIP bool8489 // If enabled, the url.RawPath will be used to find parameters.90 UseRawPath bool91 // If true, the path value will be unescaped.92 // If UseRawPath is false (by default), the UnescapePathValues effectively is true,93 // as url.Path gonna be used, which is already unescaped.94 UnescapePathValues bool95 }96)85 // #726 #755 If enabled, it will thrust some headers starting with86 // 'X-AppEngine...' for better integration with that PaaS.87 AppEngine bool8889 // If enabled, the url.RawPath will be used to find parameters.90 UseRawPath bool91 // If true, the path value will be unescaped.92 // If UseRawPath is false (by default), the UnescapePathValues effectively is true,93 // as url.Path gonna be used, which is already unescaped.94 UnescapePathValues bool95}9697var _ IRouter = &Engine{}9899// New returns a new blank Engine instance without any middleware attached.100// By default the configuration is:
317 unmodified lines
modified:response_writer.go+22 added-24 removed
14 unmodified lines
15 noWritten = -116 defaultStatus = 20017)1819type (20 ResponseWriter interface {21 http.ResponseWriter22 http.Hijacker23 http.Flusher24 http.CloseNotifier19type ResponseWriter interface {20 http.ResponseWriter21 http.Hijacker22 http.Flusher23 http.CloseNotifier2426 // Returns the HTTP response status code of the current request.27 Status() int25 // Returns the HTTP response status code of the current request.26 Status() int2729 // Returns the number of bytes already written into the response http body.30 // See Written()31 Size() int28 // Returns the number of bytes already written into the response http body.29 // See Written()30 Size() int3133 // Writes the string into the response body.34 WriteString(string) (int, error)32 // Writes the string into the response body.33 WriteString(string) (int, error)3436 // Returns true if the response body was already written.37 Written() bool35 // Returns true if the response body was already written.36 Written() bool3739 // Forces to write the http header (status code + headers).40 WriteHeaderNow()41 }38 // Forces to write the http header (status code + headers).39 WriteHeaderNow()40}4143 responseWriter struct {44 http.ResponseWriter45 size int46 status int47 }48)42type responseWriter struct {43 http.ResponseWriter44 size int45 status int46}4748var _ ResponseWriter = &responseWriter{}4950func (w *responseWriter) reset(writer http.ResponseWriter) {
64 unmodified lines
modified:routergroup.go+27 added-29 removed
9 unmodified lines
10 "regexp"11 "strings"12)1314type (15 IRouter interface {16 IRoutes17 Group(string, ...HandlerFunc) *RouterGroup18 }14type IRouter interface {15 IRoutes16 Group(string, ...HandlerFunc) *RouterGroup17}1820 IRoutes interface {21 Use(...HandlerFunc) IRoutes19type IRoutes interface {20 Use(...HandlerFunc) IRoutes2123 Handle(string, string, ...HandlerFunc) IRoutes24 Any(string, ...HandlerFunc) IRoutes25 GET(string, ...HandlerFunc) IRoutes26 POST(string, ...HandlerFunc) IRoutes27 DELETE(string, ...HandlerFunc) IRoutes28 PATCH(string, ...HandlerFunc) IRoutes29 PUT(string, ...HandlerFunc) IRoutes30 OPTIONS(string, ...HandlerFunc) IRoutes31 HEAD(string, ...HandlerFunc) IRoutes22 Handle(string, string, ...HandlerFunc) IRoutes23 Any(string, ...HandlerFunc) IRoutes24 GET(string, ...HandlerFunc) IRoutes25 POST(string, ...HandlerFunc) IRoutes26 DELETE(string, ...HandlerFunc) IRoutes27 PATCH(string, ...HandlerFunc) IRoutes28 PUT(string, ...HandlerFunc) IRoutes29 OPTIONS(string, ...HandlerFunc) IRoutes30 HEAD(string, ...HandlerFunc) IRoutes3133 StaticFile(string, string) IRoutes34 Static(string, string) IRoutes35 StaticFS(string, http.FileSystem) IRoutes36 }32 StaticFile(string, string) IRoutes33 Static(string, string) IRoutes34 StaticFS(string, http.FileSystem) IRoutes35}3638 // RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix39 // and an array of handlers (middleware)40 RouterGroup struct {41 Handlers HandlersChain42 basePath string43 engine *Engine44 root bool45 }46)37// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix38// and an array of handlers (middleware)39type RouterGroup struct {40 Handlers HandlersChain41 basePath string42 engine *Engine43 root bool44}4546var _ IRouter = &RouterGroup{}4748// Use adds middleware to the group, see example code in github.
165 unmodified lines