Skip to content
Myr

Merge pull request #33 from jasonrhansen/master

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

Fix spelling and grammar errors in comments

authored by Manu Mtz.-Almeida · committed by Manu Mtz.-Almeida · parents f0282c8, fd30d28 · Browse files · 1 file+16 added−16 removed
This commit

State

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

Diff stats

1 file+16 added−16 removed

  • other:+16 added−16 removed

1 file+16 added−16 removed

modified:gin.go+16 added-16 removed
21 unmodified lines
22 HandlerFunc func(*Context)2324 H map[string]interface{}2526 // Used internally to collect a error ocurred during a http request.26 // Used internally to collect errors that occurred during an http request.27 ErrorMsg struct {28 Err string `json:"error"`29 Meta interface{} `json:"meta"`30 }
21 unmodified lines
52 parent *RouterGroup53 engine *Engine54 }5556 // Represents the web framework, it wrappers the blazing fast httprouter multiplexer and a list of global middlewares.56 // Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middlewares.57 Engine struct {58 *RouterGroup59 handlers404 []HandlerFunc60 router *httprouter.Router
90 unmodified lines
151func (group *RouterGroup) Use(middlewares ...HandlerFunc) {152 group.Handlers = append(group.Handlers, middlewares...)153}154155// Greates a new router group. You should create add all the routes that share that have common middlwares or same path prefix.155// Creates a new router group. You should add all the routes that have common middlwares or the same path prefix.156// For example, all the routes that use a common middlware for authorization could be grouped.157func (group *RouterGroup) Group(component string, handlers ...HandlerFunc) *RouterGroup {158 prefix := path.Join(group.prefix, component)159 return &RouterGroup{
77 unmodified lines
237 c.Writer.WriteHeader(code)238 c.index = AbortIndex239}240241// Fail is the same than Abort plus an error message.241// Fail is the same as Abort plus an error message.242// Calling `context.Fail(500, err)` is equivalent to:243// ```244// context.Error("Operation aborted", err)245// context.Abort(500)
2 unmodified lines
248 c.Error(err, "Operation aborted")249 c.Abort(code)250}251252// Attachs an error to the current context. The error is pushed to a list of errors.253// It's a gooc idea to call Error for each error ocurred during the resolution of a request.252// Attaches an error to the current context. The error is pushed to a list of errors.253// It's a good idea to call Error for each error that occurred during the resolution of a request.254// 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.255func (c *Context) Error(err error, meta interface{}) {256 c.Errors = append(c.Errors, ErrorMsg{257 Err: err.Error(),
13 unmodified lines
271/************************************/272/******** METADATA MANAGEMENT********/273/************************************/274275// Sets a new pair key/value just for the specefied context.276// It also lazy initializes the hashmap275// Sets a new pair key/value just for the specified context.276// It also lazy initializes the hashmap.277func (c *Context) Set(key string, item interface{}) {278 if c.Keys == nil {279 c.Keys = make(map[string]interface{})280 }
38 unmodified lines
319 return err320 }321}322323// Serializes the given struct as a JSON into the response body in a fast and efficient way.324// It also sets the Content-Type as "application/json"323// Serializes the given struct as JSON into the response body in a fast and efficient way.324// It also sets the Content-Type as "application/json".325func (c *Context) JSON(code int, obj interface{}) {326 c.Writer.Header().Set("Content-Type", "application/json")327 if code >= 0 {328 c.Writer.WriteHeader(code)
4 unmodified lines
333 http.Error(c.Writer, err.Error(), 500)334 }335}336337// Serializes the given struct as a XML into the response body in a fast and efficient way.338// It also sets the Content-Type as "application/xml"337// Serializes the given struct as XML into the response body in a fast and efficient way.338// It also sets the Content-Type as "application/xml".339func (c *Context) XML(code int, obj interface{}) {340 c.Writer.Header().Set("Content-Type", "application/xml")341 if code >= 0 {342 c.Writer.WriteHeader(code)
4 unmodified lines
347 http.Error(c.Writer, err.Error(), 500)348 }349}350351// Renders the HTTP template specified by his file name.352// It also update the HTTP code and sets the Content-Type as "text/html".351// Renders the HTTP template specified by its file name.352// It also updates the HTTP code and sets the Content-Type as "text/html".353// See http://golang.org/doc/articles/wiki/354func (c *Context) HTML(code int, name string, data interface{}) {355 c.Writer.Header().Set("Content-Type", "text/html")356 if code >= 0 {
7 unmodified lines
364 http.Error(c.Writer, err.Error(), 500)365 }366}367368// Writes the given string into the response body and sets the Content-Type to "text/plain"368// Writes the given string into the response body and sets the Content-Type to "text/plain".369func (c *Context) String(code int, msg string) {370 if code >= 0 {371 c.Writer.WriteHeader(code)372 }373 c.Writer.Header().Set("Content-Type", "text/plain")374 c.Writer.Write([]byte(msg))375}376377// Writes some data into the body stream and updates the HTTP code377// Writes some data into the body stream and updates the HTTP code.378func (c *Context) Data(code int, data []byte) {379 c.Writer.WriteHeader(code)380 c.Writer.Write(data)381}