diff --git a/context.go b/context.go index 8fa389e..13056ee 100644 --- a/context.go +++ b/context.go @@ -39,7 +39,7 @@ type Context struct { var NoJsonBody = errors.New("jas.Context: no json body") -//Write and flush the data. +// FlushData writes and flush the data. //It can be used for http streaming or to write a portion of large amount of data. //If the type of the data is not []byte, it will be marshaled to json format. func (ctx *Context) FlushData(data interface{}) (written int, err error) { @@ -74,12 +74,12 @@ func (ctx *Context) FlushData(data interface{}) (written int, err error) { return } -//Add response header Set-Cookie. +// SetCookie adds response header Set-Cookie. func (ctx *Context) SetCookie(cookie *http.Cookie) { ctx.ResponseHeader.Add("Set-Cookie", cookie.String()) } -//override *http.Request AddCookie method to add response header's cookie. +// override *http.Request AddCookie method to add response header's cookie. //Same as SetCookie. func (ctx *Context) AddCookie(cookie *http.Cookie) { ctx.ResponseHeader.Add("Set-Cookie", cookie.String()) @@ -135,7 +135,7 @@ func (ctx *Context) deferredResponse() { } } -//Typically used in for loop condition.along with Flush. +// Typically used in for loop condition.along with Flush. func (ctx *Context) ClientClosed() bool { if ctx.clientClosed { return true @@ -148,7 +148,7 @@ func (ctx *Context) ClientClosed() bool { return ctx.clientClosed } -//the segment index starts at the resource segment +// The segment index starts at the resource segment func (ctx *Context) PathSegment(index int) string { if len(ctx.pathSegments) <= index { return "" @@ -156,7 +156,7 @@ func (ctx *Context) PathSegment(index int) string { return ctx.pathSegments[index] } -//If the gap has multiple segments, the key should be +// If the gap has multiple segments, the key should be //the segment defined in resource Gap method. //e.g. for gap ":domain/:language", use key ":domain" //to get the first gap segment, use key ":language" to get the second gap segment. @@ -173,7 +173,7 @@ func (ctx *Context) GapSegment(key string) string { return "" } -//It is an convenient method to validate and get the user id. +// It is an convenient method to validate and get the user id. func (ctx *Context) RequireUserId() int64 { if ctx.UserId <= 0 { requerstError := NewRequestError("Unauthorized") @@ -197,7 +197,7 @@ func (ctx *Context) Unmarshal(in interface{}) error { return NoJsonBody } -//If set Config option `DisableAutoUnmarshal` to true, you should call this method first before you can get body parameters in Finder methods.. +// If set Config option `DisableAutoUnmarshal` to true, you should call this method first before you can get body parameters in Finder methods.. func (ctx *Context) UnmarshalInFinder() { if ctx.value == nil && ctx.ContentLength > 0 && strings.Contains(ctx.Header.Get("Content-Type"), "application/json") { var in interface{} diff --git a/error.go b/error.go index 9e9f8c1..507f7d1 100644 --- a/error.go +++ b/error.go @@ -132,12 +132,12 @@ func doLog(logger *log.Logger, context *Context, err error, stack string) { ) } -//Make an RequestError with message which will be sent to the client. +// Make an RequestError with message which will be sent to the client. func NewRequestError(message string) RequestError { return RequestError{message, RequestErrorStatusCode} } -//Wrap an error to InternalError +// Wrap an error to InternalError func NewInternalError(err interface{}) InternalError { e, ok := err.(error) if !ok { diff --git a/finder.go b/finder.go index 45c0df0..9a2f9c5 100644 --- a/finder.go +++ b/finder.go @@ -284,7 +284,7 @@ func (finder Finder) FindBool(paths ...interface{}) (bool, error) { return false, WrongTypeError } -// return the length of []interface or map[string]interface{} +// Len returns the length of []interface or map[string]interface{} // return -1 if the value not found or has wrong type. func (finder Finder) Len(paths ...interface{}) int { finder = finder.FindChild(paths...) @@ -325,14 +325,14 @@ func (finder Finder) FindChild(paths ...interface{}) Finder { return finder } -//Construct a Finder with *http.Request. +// Construct a Finder with *http.Request. func FinderWithRequest(req *http.Request) Finder { finder := Finder{} finder.req = req return finder } -//Construct a Finder with json formatted data. +// Construct a Finder with json formatted data. func FinderWithBytes(data []byte) Finder { finder := Finder{} var in interface{} diff --git a/router.go b/router.go index 1dc583c..c9cf393 100644 --- a/router.go +++ b/router.go @@ -90,7 +90,7 @@ type Config struct { AllowIntegerGap bool } -//Implements http.Handler interface. +// Implements http.Handler interface. func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { if !strings.HasPrefix(r.URL.Path, router.BasePath) { router.OnNotFound(w, r) @@ -142,7 +142,7 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -//Get the paths that have been handled by resources. +// HandledPaths gets the paths that have been handled by resources. //The paths are sorted, it can be used to detect api path changes. func (r *Router) HandledPaths(withBasePath bool) string { var handledPaths []string @@ -275,7 +275,7 @@ func notFound(w http.ResponseWriter, r *http.Request) { w.Write(jsonbytes) } -//This is an implementation of HandleCORS function to allow all cross domain request. +// AllowCORS is an implementation of HandleCORS function to allow all cross domain request. func AllowCORS(r *http.Request, responseHeader http.Header) bool { responseHeader.Add("Access-Control-Allow-Origin", "*") if r.Method == "OPTIONS" {