Skip to content

Commit

Permalink
update comment (gin-gonic#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Yip committed Feb 20, 2018
1 parent 22f3334 commit fff0273
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 46 deletions.
8 changes: 4 additions & 4 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"strconv"
)

// 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"

// 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

type authPair struct {
Expand Down Expand Up @@ -56,7 +56,7 @@ func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc {
}

// The user credentials was found, set user's id to key AuthUserKey in this context, the user's id can be read later using
// c.MustGet(gin.AuthUserKey)
// c.MustGet(gin.AuthUserKey).
c.Set(AuthUserKey, user)
}
}
Expand Down Expand Up @@ -90,6 +90,6 @@ func secureCompare(given, actual string) bool {
if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 {
return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1
}
// Securely compare actual to itself to keep constant time, but always return false
// Securely compare actual to itself to keep constant time, but always return false.
return subtle.ConstantTimeCompare([]byte(actual), []byte(actual)) == 1 && false
}
29 changes: 14 additions & 15 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/gin-gonic/gin/render"
)

// Content-Type MIME of the most common data formats
// Content-Type MIME of the most common data formats.
const (
MIMEJSON = binding.MIMEJSON
MIMEHTML = binding.MIMEHTML
Expand Down Expand Up @@ -49,13 +49,13 @@ type Context struct {

engine *Engine

// Keys is a key/value pair exclusively for the context of each request
// Keys is a key/value pair exclusively for the context of each request.
Keys map[string]interface{}

// Errors is a list of errors attached to all the handlers/middlewares who used this context
// Errors is a list of errors attached to all the handlers/middlewares who used this context.
Errors errorMsgs

// Accepted defines a list of manually accepted formats for content negotiation
// Accepted defines a list of manually accepted formats for content negotiation.
Accepted []string
}

Expand Down Expand Up @@ -84,8 +84,8 @@ func (c *Context) Copy() *Context {
return &cp
}

// HandlerName returns the main handler's name. For example if the handler is "handleGetUsers()", this
// function will return "main.handleGetUsers"
// HandlerName returns the main handler's name. For example if the handler is "handleGetUsers()",
// this function will return "main.handleGetUsers".
func (c *Context) HandlerName() string {
return nameOfFunction(c.handlers.Last())
}
Expand Down Expand Up @@ -441,13 +441,13 @@ func (c *Context) Bind(obj interface{}) error {
return c.MustBindWith(obj, b)
}

// BindJSON is a shortcut for c.MustBindWith(obj, binding.JSON)
// BindJSON is a shortcut for c.MustBindWith(obj, binding.JSON).
func (c *Context) BindJSON(obj interface{}) error {
return c.MustBindWith(obj, binding.JSON)
}

// MustBindWith binds the passed struct pointer using the specified binding
// engine. It will abort the request with HTTP 400 if any error ocurrs.
// MustBindWith binds the passed struct pointer using the specified binding engine.
// It will abort the request with HTTP 400 if any error ocurrs.
// See the binding package.
func (c *Context) MustBindWith(obj interface{}, b binding.Binding) (err error) {
if err = c.ShouldBindWith(obj, b); err != nil {
Expand All @@ -457,8 +457,7 @@ func (c *Context) MustBindWith(obj interface{}, b binding.Binding) (err error) {
return
}

// ShouldBindWith binds the passed struct pointer using the specified binding
// engine.
// ShouldBindWith binds the passed struct pointer using the specified binding engine.
// See the binding package.
func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error {
return b.Bind(c.Request, obj)
Expand Down Expand Up @@ -522,7 +521,7 @@ func (c *Context) requestHeader(key string) string {
/******** RESPONSE RENDERING ********/
/************************************/

// bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function
// bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function.
func bodyAllowedForStatus(status int) bool {
switch {
case status >= 100 && status <= 199:
Expand All @@ -539,7 +538,7 @@ func (c *Context) Status(code int) {
c.writermem.WriteHeader(code)
}

// Header is a intelligent shortcut for c.Writer.Header().Set(key, value)
// Header is a intelligent shortcut for c.Writer.Header().Set(key, value).
// It writes a header in the response.
// If value == "", this method removes the header `c.Writer.Header().Del(key)`
func (c *Context) Header(key, value string) {
Expand All @@ -550,12 +549,12 @@ func (c *Context) Header(key, value string) {
}
}

// GetHeader returns value from request headers
// GetHeader returns value from request headers.
func (c *Context) GetHeader(key string) string {
return c.requestHeader(key)
}

// GetRawData return stream data
// GetRawData return stream data.
func (c *Context) GetRawData() ([]byte, error) {
return ioutil.ReadAll(c.Request.Body)
}
Expand Down
6 changes: 3 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (msg *Error) JSON() interface{} {
return json
}

// MarshalJSON implements the json.Marshaller interface
// MarshalJSON implements the json.Marshaller interface.
func (msg *Error) MarshalJSON() ([]byte, error) {
return json.Marshal(msg.JSON())
}
Expand All @@ -79,7 +79,7 @@ func (msg *Error) IsType(flags ErrorType) bool {
}

// ByType returns a readonly copy filtered the byte.
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic
// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic.
func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
if len(a) == 0 {
return nil
Expand All @@ -97,7 +97,7 @@ func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
}

// Last returns the last error in the slice. It returns nil if the array is empty.
// Shortcut for errors[len(errors)-1]
// Shortcut for errors[len(errors)-1].
func (a errorMsgs) Last() *Error {
if length := len(a); length > 0 {
return a[length-1]
Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Dir(root string, listDirectory bool) http.FileSystem {
return &onlyfilesFS{fs}
}

// Open 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 {
Expand All @@ -38,7 +38,7 @@ func (fs onlyfilesFS) Open(name string) (http.File, error) {
return neuteredReaddirFile{f}, nil
}

// Readdir 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
Expand Down
4 changes: 2 additions & 2 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/gin-gonic/gin/render"
)

// Version is Framework's version
// Version is Framework's version.
const Version = "v1.2"

var default404Body = []byte("404 page not found")
Expand Down Expand Up @@ -191,7 +191,7 @@ func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
engine.rebuild404Handlers()
}

// NoMethod sets the handlers called when... TODO
// NoMethod sets the handlers called when... TODO.
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
engine.noMethod = handlers
engine.rebuild405Handlers()
Expand Down
7 changes: 5 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ var (
disableColor = false
)

// DisableConsoleColor disables color output in the console.
func DisableConsoleColor() {
disableColor = true
}

// ErrorLogger returns a handlerfunc for any error type.
func ErrorLogger() HandlerFunc {
return ErrorLoggerT(ErrorTypeAny)
}

// ErrorLoggerT returns a handlerfunc for a given error type.
func ErrorLoggerT(typ ErrorType) HandlerFunc {
return func(c *Context) {
c.Next()
Expand All @@ -43,8 +46,8 @@ func ErrorLoggerT(typ ErrorType) HandlerFunc {
}
}

// Logger instances a Logger middleware that will write the logs to gin.DefaultWriter
// By default gin.DefaultWriter = os.Stdout
// Logger instances a Logger middleware that will write the logs to gin.DefaultWriter.
// By default gin.DefaultWriter = os.Stdout.
func Logger() HandlerFunc {
return LoggerWithWriter(DefaultWriter)
}
Expand Down
4 changes: 2 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package gin
// 4. Eliminate .. elements that begin a rooted path:
// that is, replace "/.." by "/" at the beginning of a path.
//
// If the result of this process is an empty string, "/" is returned
// If the result of this process is an empty string, "/" is returned.
func cleanPath(p string) string {
// Turn empty string into "/"
if p == "" {
Expand Down Expand Up @@ -109,7 +109,7 @@ func cleanPath(p string) string {
return string(buf[:w])
}

// internal helper to lazily create a buffer if necessary
// internal helper to lazily create a buffer if necessary.
func bufApp(buf *[]byte, s string, w int, c byte) {
if *buf == nil {
if s[w] == c {
Expand Down
2 changes: 1 addition & 1 deletion recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc {
}
}

// stack returns a nicely formated stack frame, skipping skip frames
// stack returns a nicely formated stack frame, skipping skip frames.
func stack(skip int) []byte {
buf := new(bytes.Buffer) // the returned data
// As we loop, we open files and read them. These variables record the currently
Expand Down
2 changes: 1 addition & 1 deletion render/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Data struct {
Data []byte
}

// Render (Data) writes data with custom ContentType
// Render (Data) writes data with custom ContentType.
func (r Data) Render(w http.ResponseWriter) (err error) {
r.WriteContentType(w)
_, err = w.Write(r.Data)
Expand Down
6 changes: 3 additions & 3 deletions response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ func (w *responseWriter) Written() bool {
return w.size != noWritten
}

// Hijack 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
}
return w.ResponseWriter.(http.Hijacker).Hijack()
}

// CloseNotify implements the http.CloseNotify interface
// CloseNotify implements the http.CloseNotify interface.
func (w *responseWriter) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}

// Flush implements the http.Flush interface
// Flush implements the http.Flush interface.
func (w *responseWriter) Flush() {
w.ResponseWriter.(http.Flusher).Flush()
}
18 changes: 9 additions & 9 deletions routergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type IRoutes interface {
}

// 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).
type RouterGroup struct {
Handlers HandlersChain
basePath string
Expand Down Expand Up @@ -89,43 +89,43 @@ func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...Ha
return group.handle(httpMethod, relativePath, handlers)
}

// POST is a shortcut for router.Handle("POST", path, handle)
// POST is a shortcut for router.Handle("POST", path, handle).
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("POST", relativePath, handlers)
}

// GET is a shortcut for router.Handle("GET", path, handle)
// GET is a shortcut for router.Handle("GET", path, handle).
func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("GET", relativePath, handlers)
}

// DELETE is a shortcut for router.Handle("DELETE", path, handle)
// DELETE is a shortcut for router.Handle("DELETE", path, handle).
func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("DELETE", relativePath, handlers)
}

// PATCH is a shortcut for router.Handle("PATCH", path, handle)
// PATCH is a shortcut for router.Handle("PATCH", path, handle).
func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("PATCH", relativePath, handlers)
}

// PUT is a shortcut for router.Handle("PUT", path, handle)
// PUT is a shortcut for router.Handle("PUT", path, handle).
func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("PUT", relativePath, handlers)
}

// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)
// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("OPTIONS", relativePath, handlers)
}

// HEAD is a shortcut for router.Handle("HEAD", path, handle)
// HEAD is a shortcut for router.Handle("HEAD", path, handle).
func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes {
return group.handle("HEAD", relativePath, handlers)
}

// Any registers a route that matches all the HTTP methods.
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
group.handle("GET", relativePath, handlers)
group.handle("POST", relativePath, handlers)
Expand Down
2 changes: 1 addition & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type node struct {
priority uint32
}

// increments priority of the given child and reorders if necessary
// increments priority of the given child and reorders if necessary.
func (n *node) incrementChildPrio(pos int) int {
n.children[pos].priority++
prio := n.children[pos].priority
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WrapH(h http.Handler) HandlerFunc {

type H map[string]interface{}

// MarshalXML allows type H to be used with xml.Marshal
// MarshalXML allows type H to be used with xml.Marshal.
func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name = xml.Name{
Space: "",
Expand Down

0 comments on commit fff0273

Please sign in to comment.