forked from mirror/gin
update func comment (#981)
This commit is contained in:
parent
22ee916dfe
commit
b985857899
|
@ -151,7 +151,7 @@ func (c *Context) AbortWithError(code int, err error) *Error {
|
|||
/********* ERROR MANAGEMENT *********/
|
||||
/************************************/
|
||||
|
||||
// Attaches an error to the current context. The error is pushed to a list of errors.
|
||||
// Error attaches an error to the current context. The error is pushed to a list of errors.
|
||||
// It's a good idea to call Error for each error that occurred during the resolution of a request.
|
||||
// A middleware can be used to collect all the errors
|
||||
// and push them to a database together, print a log, or append it in the HTTP response.
|
||||
|
|
11
errors.go
11
errors.go
|
@ -69,7 +69,7 @@ func (msg *Error) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(msg.JSON())
|
||||
}
|
||||
|
||||
// Implements the error interface
|
||||
// Error implements the error interface
|
||||
func (msg Error) Error() string {
|
||||
return msg.Err.Error()
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func (msg *Error) IsType(flags ErrorType) bool {
|
|||
return (msg.Type & flags) > 0
|
||||
}
|
||||
|
||||
// Returns a readonly copy filtered the byte.
|
||||
// ByType returns a readonly copy filtered the byte.
|
||||
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
|
||||
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
||||
if len(a) == 0 {
|
||||
|
@ -96,17 +96,16 @@ func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
|
|||
return result
|
||||
}
|
||||
|
||||
// Returns the last error in the slice. It returns nil if the array is empty.
|
||||
// Last returns the last error in the slice. It returns nil if the array is empty.
|
||||
// Shortcut for errors[len(errors)-1]
|
||||
func (a errorMsgs) Last() *Error {
|
||||
length := len(a)
|
||||
if length > 0 {
|
||||
if length := len(a); length > 0 {
|
||||
return a[length-1]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns an array will all the error messages.
|
||||
// Errors returns an array will all the error messages.
|
||||
// Example:
|
||||
// c.Error(errors.New("first"))
|
||||
// c.Error(errors.New("second"))
|
||||
|
|
4
fs.go
4
fs.go
|
@ -29,7 +29,7 @@ func Dir(root string, listDirectory bool) http.FileSystem {
|
|||
return &onlyfilesFS{fs}
|
||||
}
|
||||
|
||||
// Conforms to http.Filesystem
|
||||
// Open conforms to http.Filesystem
|
||||
func (fs onlyfilesFS) Open(name string) (http.File, error) {
|
||||
f, err := fs.fs.Open(name)
|
||||
if err != nil {
|
||||
|
@ -38,7 +38,7 @@ func (fs onlyfilesFS) Open(name string) (http.File, error) {
|
|||
return neuteredReaddirFile{f}, nil
|
||||
}
|
||||
|
||||
// Overrides the http.File default implementation
|
||||
// Readdir overrides the http.File default implementation
|
||||
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
// this disables directory listing
|
||||
return nil, nil
|
||||
|
|
4
gin.go
4
gin.go
|
@ -285,7 +285,7 @@ func (engine *Engine) RunUnix(file string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Conforms to the http.Handler interface.
|
||||
// ServeHTTP conforms to the http.Handler interface.
|
||||
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
c := engine.pool.Get().(*Context)
|
||||
c.writermem.reset(w)
|
||||
|
@ -297,7 +297,7 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
engine.pool.Put(c)
|
||||
}
|
||||
|
||||
// Re-enter a context that has been rewritten.
|
||||
// HandleContext re-enter a context that has been rewritten.
|
||||
// This can be done by setting c.Request.Path to your new target.
|
||||
// Disclaimer: You can loop yourself to death with this, use wisely.
|
||||
func (engine *Engine) HandleContext(c *Context) {
|
||||
|
|
|
@ -95,7 +95,7 @@ func (w *responseWriter) Written() bool {
|
|||
return w.size != noWritten
|
||||
}
|
||||
|
||||
// Implements the http.Hijacker interface
|
||||
// Hijack implements the http.Hijacker interface
|
||||
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
if w.size < 0 {
|
||||
w.size = 0
|
||||
|
@ -103,12 +103,12 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|||
return w.ResponseWriter.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
// Implements the http.CloseNotify interface
|
||||
// CloseNotify implements the http.CloseNotify interface
|
||||
func (w *responseWriter) CloseNotify() <-chan bool {
|
||||
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
|
||||
}
|
||||
|
||||
// Implements the http.Flush interface
|
||||
// Flush implements the http.Flush interface
|
||||
func (w *responseWriter) Flush() {
|
||||
w.ResponseWriter.(http.Flusher).Flush()
|
||||
}
|
||||
|
|
4
tree.go
4
tree.go
|
@ -357,7 +357,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
|
|||
n.handlers = handlers
|
||||
}
|
||||
|
||||
// Returns the handle registered with the given path (key). The values of
|
||||
// getValue returns the handle registered with the given path (key). The values of
|
||||
// wildcards are saved to a map.
|
||||
// If no handle can be found, a TSR (trailing slash redirect) recommendation is
|
||||
// made if a handle exists with an extra (without the) trailing slash for the
|
||||
|
@ -499,7 +499,7 @@ walk: // Outer loop for walking the tree
|
|||
}
|
||||
}
|
||||
|
||||
// Makes a case-insensitive lookup of the given path and tries to find a handler.
|
||||
// findCaseInsensitivePath makes a case-insensitive lookup of the given path and tries to find a handler.
|
||||
// It can optionally also fix trailing slashes.
|
||||
// It returns the case-corrected path and a bool indicating whether the lookup
|
||||
// was successful.
|
||||
|
|
Loading…
Reference in New Issue