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
Provenance
- Commit
d535fcd- Tree
b47c30c- Author
田欧 <thinkerou@gmail.com>- Committer
Bo-Yi Wu <appleboy.tw@gmail.com>- Parent
22fc028
6 files changed+125 added−133 removed
modified:auth.go+9 added-9 removed
11 unmodified lines12 13 // AuthUserKey is the cookie name for user credential in basic auth14 const AuthUserKey = "user"15 16-type (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 logins17+type Accounts map[string]string19- authPair struct {20- Value string21- User string22- }23- authPairs []authPair24-)18 19+type authPair struct {20+ Value string21+ User string22+}23+24+type authPairs []authPair25+26 func (a authPairs) searchCredential(authValue string) (string, bool) {27 if len(authValue) == 0 {28 return "", false29 }65 unmodified linesmodified:errors.go+6 added-8 removed
21 unmodified lines22 ErrorTypeAny ErrorType = 1<<64 - 123 ErrorTypeNu = 224 )25 26-type (27- Error struct {28- Err error29- Type ErrorType30- Meta interface{}31- }26+type Error struct {27+ Err error28+ Type ErrorType29+ Meta interface{}30+}31 33- errorMsgs []*Error34-)32+type errorMsgs []*Error33 34 var _ error = &Error{}35 36 func (msg *Error) SetType(flags ErrorType) *Error {121 unmodified linesmodified:fs.go+7 added-8 removed
7 unmodified lines8 "net/http"9 "os"10 )11 12-type (13- onlyfilesFS struct {14- fs http.FileSystem15- }12+type onlyfilesFS struct {13+ fs http.FileSystem14+}16- neuteredReaddirFile struct {17- http.File18- }19-)15 16+type neuteredReaddirFile struct {17+ http.File18+}19+20 // 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 linesmodified:gin.go+54 added-55 removed
31 unmodified lines32 }33 return nil34 }35 36-type (37- RoutesInfo []RouteInfo38- RouteInfo struct {39- Method string40- Path string41- Handler string42- }36+type RouteInfo struct {37+ Method string38+ Path string39+ Handler string40+}41 44- // 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 methodTrees42+type RoutesInfo []RouteInfo43 58- // 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()46+type 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 methodTrees57 65- // 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 bool64 76- // 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 bool75 85- // #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 bool84 89- // 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 bool88 89+ // 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+97 var _ IRouter = &Engine{}98 99 // New returns a new blank Engine instance without any middleware attached.100 // By default the configuration is:317 unmodified linesmodified:response_writer.go+22 added-24 removed
14 unmodified lines15 noWritten = -116 defaultStatus = 20017 )18 19-type (20- ResponseWriter interface {21- http.ResponseWriter22- http.Hijacker23- http.Flusher24- http.CloseNotifier19+type ResponseWriter interface {20+ http.ResponseWriter21+ http.Hijacker22+ http.Flusher23+ http.CloseNotifier24 26- // 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() int27 29- // 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() int31 33- // 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)34 36- // Returns true if the response body was already written.37- Written() bool35+ // Returns true if the response body was already written.36+ Written() bool37 39- // 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+}41 43- responseWriter struct {44- http.ResponseWriter45- size int46- status int47- }48-)42+type responseWriter struct {43+ http.ResponseWriter44+ size int45+ status int46+}47 48 var _ ResponseWriter = &responseWriter{}49 50 func (w *responseWriter) reset(writer http.ResponseWriter) {64 unmodified linesmodified:routergroup.go+27 added-29 removed
9 unmodified lines10 "regexp"11 "strings"12 )13 14-type (15- IRouter interface {16- IRoutes17- Group(string, ...HandlerFunc) *RouterGroup18- }14+type IRouter interface {15+ IRoutes16+ Group(string, ...HandlerFunc) *RouterGroup17+}18 20- IRoutes interface {21- Use(...HandlerFunc) IRoutes19+type IRoutes interface {20+ Use(...HandlerFunc) IRoutes21 23- 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) IRoutes31 33- 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+}36 38- // 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)39+type RouterGroup struct {40+ Handlers HandlersChain41+ basePath string42+ engine *Engine43+ root bool44+}45 46 var _ IRouter = &RouterGroup{}47 48 // Use adds middleware to the group, see example code in github.165 unmodified lines