chore: add some annotations (#1550)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
ref #1075 should all annotations and can close #1075 .
authored by 田欧 · committed by Bo-Yi Wu · parent d510595 · Browse files · 7 files·+47 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+47 added−12 removed
- other:+47 added−12 removed
Provenance
- Commit
6db092f- Tree
96c1d10- Author
田欧 <thinkerou@gmail.com>- Committer
Bo-Yi Wu <appleboy.tw@gmail.com>- Parent
d510595
7 files changed+47 added−12 removed
modified:examples/realtime-advanced/main.go+1 added-1 removed
18 unmodified lines19 runtime.GOMAXPROCS(nuCPU)20 fmt.Printf("Running with %d CPUs\n", nuCPU)21 }22 23-// StartWrokers start starsWorker by goroutine.23+// StartWorkers start starsWorker by goroutine.24 func StartWorkers() {25 go statsWorker()26 }27 15 unmodified linesmodified:render/html.go+2 added-2 removed
44 unmodified lines45 }46 47 var htmlContentType = []string{"text/html; charset=utf-8"}48 49-// Instance (HTMLProduction) returns an HTML instance which it realizes Render interface..49+// Instance (HTMLProduction) returns an HTML instance which it realizes Render interface.50 func (r HTMLProduction) Instance(name string, data interface{}) Render {51 return HTML{52 Template: r.Template,53 Name: name,54 Data: data,55 }56 }57 58-// Instance (HTMLDebug) returns an HTML instance which it realizes Render interface..58+// Instance (HTMLDebug) returns an HTML instance which it realizes Render interface.59 func (r HTMLDebug) Instance(name string, data interface{}) Render {60 return HTML{61 Template: r.loadTemplate(),62 Name: name,30 unmodified linesmodified:context.go+6 added
709 unmodified lines710 val, _ := url.QueryUnescape(cookie.Value)711 return val, nil712 }713 714+// Render writes the response headers and calls render.Render to render data.715 func (c *Context) Render(code int, r render.Render) {716 c.Status(code)717 718 if !bodyAllowedForStatus(code) {114 unmodified lines833 Data: message,834 })835 }836 837+// Stream sends a streaming response.838 func (c *Context) Stream(step func(w io.Writer) bool) {839 w := c.Writer840 clientGone := w.CloseNotify()841 for {13 unmodified lines855 /************************************/856 /******** CONTENT NEGOTIATION *******/857 /************************************/858 859+// Negotiate contains all negotiations data.860 type Negotiate struct {861 Offered []string862 HTMLName string863 HTMLData interface{}1 unmodified line865 XMLData interface{}866 Data interface{}867 }868 869+// Negotiate calls different Render according acceptable Accept format.870 func (c *Context) Negotiate(code int, config Negotiate) {871 switch c.NegotiateFormat(config.Offered...) {872 case binding.MIMEJSON:873 data := chooseData(config.JSONData, config.Data)11 unmodified lines885 c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server"))886 }887 }888 889+// NegotiateFormat returns an acceptable Accept format.890 func (c *Context) NegotiateFormat(offered ...string) string {891 assert1(len(offered) > 0, "you must provide at least one offer")892 893 if c.Accepted == nil {11 unmodified lines905 }906 return ""907 }908 909+// SetAccepted sets Accept header data.910 func (c *Context) SetAccepted(formats ...string) {911 c.Accepted = formats912 }913 41 unmodified linesmodified:errors.go+15 added-5 removed
10 unmodified lines11 12 "github.com/gin-gonic/gin/internal/json"13 )14 15+// ErrorType is an unsigned 64-bit error code as defined in the gin spec.16 type ErrorType uint6417 18 const (18- ErrorTypeBind ErrorType = 1 << 63 // used when c.Bind() fails19- ErrorTypeRender ErrorType = 1 << 62 // used when c.Render() fails19+ // ErrorTypeBind is used when Context.Bind() fails.20+ ErrorTypeBind ErrorType = 1 << 6321+ // ErrorTypeRender is used when Context.Render() fails.22+ ErrorTypeRender ErrorType = 1 << 6223+ // ErrorTypePrivate indicates a private error.24 ErrorTypePrivate ErrorType = 1 << 021- ErrorTypePublic ErrorType = 1 << 122-25+ // ErrorTypePublic indicates a public error.26+ ErrorTypePublic ErrorType = 1 << 127+ // ErrorTypeAny indicates other any error.28 ErrorTypeAny ErrorType = 1<<64 - 129 ErrorTypeNu = 230 )31 32+// Error represents a error's specification.33 type Error struct {34 Err error35 Type ErrorType36 Meta interface{}2 unmodified lines39 type errorMsgs []*Error40 41 var _ error = &Error{}42 43+// SetType sets the error's type.44 func (msg *Error) SetType(flags ErrorType) *Error {45 msg.Type = flags46 return msg47 }48 49+// SetMeta sets the error's meta data.50 func (msg *Error) SetMeta(data interface{}) *Error {51 msg.Meta = data52 return msg53 }23 unmodified lines77 func (msg *Error) MarshalJSON() ([]byte, error) {78 return json.Marshal(msg.JSON())79 }80 73-// Error implements the error interface81+// Error implements the error interface.82 func (msg Error) Error() string {83 return msg.Err.Error()84 }85 86+// IsType judges one error.87 func (msg *Error) IsType(flags ErrorType) bool {88 return (msg.Type & flags) > 089 }90 55 unmodified lines146 return json147 }148 }149 150+// MarshalJSON implements the json.Marshaller interface.151 func (a errorMsgs) MarshalJSON() ([]byte, error) {152 return json.Marshal(a.JSON())153 }154 13 unmodified linesmodified:gin.go+6 added
24 unmodified lines25 default405Body = []byte("405 method not allowed")26 defaultAppEngine bool27 )28 29+// HandlerFunc defines the handler used by gin middleware as return value.30 type HandlerFunc func(*Context)31+32+// HandlersChain defines a HandlerFunc array.33 type HandlersChain []HandlerFunc34 35 // Last returns the last handler in the chain. ie. the last handler is the main own.36 func (c HandlersChain) Last() HandlerFunc {2 unmodified lines39 }40 return nil41 }42 43+// RouteInfo represents a request route's specification which contains method and path and its handler.44 type RouteInfo struct {45 Method string46 Path string47 Handler string48 }49 50+// RoutesInfo defines a RouteInfo array.51 type RoutesInfo []RouteInfo52 53 // Engine is the framework's instance, it contains the muxer, middleware and configuration settings.54 // Create an instance of Engine, by using New() or Default()104 unmodified lines159 func (engine *Engine) allocateContext() *Context {160 return &Context{engine: engine}161 }162 163+// Delims sets template left and right delims and returns a Engine instance.164 func (engine *Engine) Delims(left, right string) *Engine {165 engine.delims = render.Delims{Left: left, Right: right}166 return engine167 }282 unmodified linesmodified:mode.go+11 added-2 removed
9 unmodified lines10 11 "github.com/gin-gonic/gin/binding"12 )13 14+// ENV_GIN_MODE indicates environment name for gin mode.15 const ENV_GIN_MODE = "GIN_MODE"16 17 const (18+ // DebugMode indicates gin mode is debug.17- DebugMode = "debug"19+ DebugMode = "debug"20+ // ReleaseMode indicates gin mode is relase.21 ReleaseMode = "release"22+ // TestMode indicates gin mode is test.19- TestMode = "test"23+ TestMode = "test"24 )25 const (26 debugCode = iota27 releaseCode17 unmodified lines45 mode := os.Getenv(ENV_GIN_MODE)46 SetMode(mode)47 }48 49+// SetMode sets gin mode according to input string.50 func SetMode(value string) {51 switch value {52 case DebugMode, "":53 ginMode = debugCode9 unmodified lines63 }64 modeName = value65 }66 67+// DisableBindValidation closes the default validator.68 func DisableBindValidation() {69 binding.Validator = nil70 }71 72+// EnableJsonDecoderUseNumber sets true for binding.EnableDecoderUseNumberto to73+// call the UseNumber method on the JSON Decoder instance.74 func EnableJsonDecoderUseNumber() {75 binding.EnableDecoderUseNumber = true76 }77 78+// Mode returns currently gin mode.79 func Mode() string {80 return modeName81 }modified:routergroup.go+6 added-2 removed
9 unmodified lines10 "regexp"11 "strings"12 )13 14+// IRouter defines all router handle interface includes single and group router.15 type IRouter interface {16 IRoutes17 Group(string, ...HandlerFunc) *RouterGroup18 }19 20+// Iroutes defins all router handle interface.21 type IRoutes interface {22 Use(...HandlerFunc) IRoutes23 24 Handle(string, string, ...HandlerFunc) IRoutes10 unmodified lines35 Static(string, string) IRoutes36 StaticFS(string, http.FileSystem) IRoutes37 }38 37-// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix38-// and an array of handlers (middleware).39+// RouterGroup is used internally to configure router, a RouterGroup is associated with40+// a prefix and an array of handlers (middleware).41 type RouterGroup struct {42 Handlers HandlersChain43 basePath string44 engine *Engine17 unmodified lines62 engine: group.engine,63 }64 }65 66+// BasePath returns the base path of router group.67+// For example, if v := router.Group("/rest/n/v1/api"), v.BasePath() is "/rest/n/v1/api".68 func (group *RouterGroup) BasePath() string {69 return group.basePath70 }71 146 unmodified lines