Skip to content
Myr

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

7 files+47 added−12 removed

modified:examples/realtime-advanced/main.go+1 added-1 removed
18 unmodified lines
19 runtime.GOMAXPROCS(nuCPU)20 fmt.Printf("Running with %d CPUs\n", nuCPU)21}2223// StartWrokers start starsWorker by goroutine.23// StartWorkers start starsWorker by goroutine.24func StartWorkers() {25 go statsWorker()26}27
15 unmodified lines
modified:render/html.go+2 added-2 removed
44 unmodified lines
45}4647var htmlContentType = []string{"text/html; charset=utf-8"}4849// Instance (HTMLProduction) returns an HTML instance which it realizes Render interface..49// Instance (HTMLProduction) returns an HTML instance which it realizes Render interface.50func (r HTMLProduction) Instance(name string, data interface{}) Render {51 return HTML{52 Template: r.Template,53 Name: name,54 Data: data,55 }56}5758// Instance (HTMLDebug) returns an HTML instance which it realizes Render interface..58// Instance (HTMLDebug) returns an HTML instance which it realizes Render interface.59func (r HTMLDebug) Instance(name string, data interface{}) Render {60 return HTML{61 Template: r.loadTemplate(),62 Name: name,
30 unmodified lines
modified:context.go+6 added
709 unmodified lines
710 val, _ := url.QueryUnescape(cookie.Value)711 return val, nil712}713714// Render writes the response headers and calls render.Render to render data.715func (c *Context) Render(code int, r render.Render) {716 c.Status(code)717718 if !bodyAllowedForStatus(code) {
114 unmodified lines
833 Data: message,834 })835}836837// Stream sends a streaming response.838func (c *Context) Stream(step func(w io.Writer) bool) {839 w := c.Writer840 clientGone := w.CloseNotify()841 for {
13 unmodified lines
855/************************************/856/******** CONTENT NEGOTIATION *******/857/************************************/858859// Negotiate contains all negotiations data.860type Negotiate struct {861 Offered []string862 HTMLName string863 HTMLData interface{}
1 unmodified line
865 XMLData interface{}866 Data interface{}867}868869// Negotiate calls different Render according acceptable Accept format.870func (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 lines
885 c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server"))886 }887}888889// NegotiateFormat returns an acceptable Accept format.890func (c *Context) NegotiateFormat(offered ...string) string {891 assert1(len(offered) > 0, "you must provide at least one offer")892893 if c.Accepted == nil {
11 unmodified lines
905 }906 return ""907}908909// SetAccepted sets Accept header data.910func (c *Context) SetAccepted(formats ...string) {911 c.Accepted = formats912}913
41 unmodified lines
modified:errors.go+15 added-5 removed
10 unmodified lines
1112 "github.com/gin-gonic/gin/internal/json"13)1415// ErrorType is an unsigned 64-bit error code as defined in the gin spec.16type ErrorType uint641718const (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 << 12225 // ErrorTypePublic indicates a public error.26 ErrorTypePublic ErrorType = 1 << 127 // ErrorTypeAny indicates other any error.28 ErrorTypeAny ErrorType = 1<<64 - 129 ErrorTypeNu = 230)3132// Error represents a error's specification.33type Error struct {34 Err error35 Type ErrorType36 Meta interface{}
2 unmodified lines
39type errorMsgs []*Error4041var _ error = &Error{}4243// SetType sets the error's type.44func (msg *Error) SetType(flags ErrorType) *Error {45 msg.Type = flags46 return msg47}4849// SetMeta sets the error's meta data.50func (msg *Error) SetMeta(data interface{}) *Error {51 msg.Meta = data52 return msg53}
23 unmodified lines
77func (msg *Error) MarshalJSON() ([]byte, error) {78 return json.Marshal(msg.JSON())79}8073// Error implements the error interface81// Error implements the error interface.82func (msg Error) Error() string {83 return msg.Err.Error()84}8586// IsType judges one error.87func (msg *Error) IsType(flags ErrorType) bool {88 return (msg.Type & flags) > 089}90
55 unmodified lines
146 return json147 }148}149150// MarshalJSON implements the json.Marshaller interface.151func (a errorMsgs) MarshalJSON() ([]byte, error) {152 return json.Marshal(a.JSON())153}154
13 unmodified lines
modified:gin.go+6 added
24 unmodified lines
25 default405Body = []byte("405 method not allowed")26 defaultAppEngine bool27)2829// HandlerFunc defines the handler used by gin middleware as return value.30type HandlerFunc func(*Context)3132// HandlersChain defines a HandlerFunc array.33type HandlersChain []HandlerFunc3435// Last returns the last handler in the chain. ie. the last handler is the main own.36func (c HandlersChain) Last() HandlerFunc {
2 unmodified lines
39 }40 return nil41}4243// RouteInfo represents a request route's specification which contains method and path and its handler.44type RouteInfo struct {45 Method string46 Path string47 Handler string48}4950// RoutesInfo defines a RouteInfo array.51type RoutesInfo []RouteInfo5253// 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 lines
159func (engine *Engine) allocateContext() *Context {160 return &Context{engine: engine}161}162163// Delims sets template left and right delims and returns a Engine instance.164func (engine *Engine) Delims(left, right string) *Engine {165 engine.delims = render.Delims{Left: left, Right: right}166 return engine167}
282 unmodified lines
modified:mode.go+11 added-2 removed
9 unmodified lines
1011 "github.com/gin-gonic/gin/binding"12)1314// ENV_GIN_MODE indicates environment name for gin mode.15const ENV_GIN_MODE = "GIN_MODE"1617const (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)25const (26 debugCode = iota27 releaseCode
17 unmodified lines
45 mode := os.Getenv(ENV_GIN_MODE)46 SetMode(mode)47}4849// SetMode sets gin mode according to input string.50func SetMode(value string) {51 switch value {52 case DebugMode, "":53 ginMode = debugCode
9 unmodified lines
63 }64 modeName = value65}6667// DisableBindValidation closes the default validator.68func DisableBindValidation() {69 binding.Validator = nil70}7172// EnableJsonDecoderUseNumber sets true for binding.EnableDecoderUseNumberto to73// call the UseNumber method on the JSON Decoder instance.74func EnableJsonDecoderUseNumber() {75 binding.EnableDecoderUseNumber = true76}7778// Mode returns currently gin mode.79func Mode() string {80 return modeName81}
modified:routergroup.go+6 added-2 removed
9 unmodified lines
10 "regexp"11 "strings"12)1314// IRouter defines all router handle interface includes single and group router.15type IRouter interface {16 IRoutes17 Group(string, ...HandlerFunc) *RouterGroup18}1920// Iroutes defins all router handle interface.21type IRoutes interface {22 Use(...HandlerFunc) IRoutes2324 Handle(string, string, ...HandlerFunc) IRoutes
10 unmodified lines
35 Static(string, string) IRoutes36 StaticFS(string, http.FileSystem) IRoutes37}3837// 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).41type RouterGroup struct {42 Handlers HandlersChain43 basePath string44 engine *Engine
17 unmodified lines
62 engine: group.engine,63 }64}6566// 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".68func (group *RouterGroup) BasePath() string {69 return group.basePath70}71
146 unmodified lines