Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -148,15 +148,15 @@ 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 ""
}
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.
Expand All @@ -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")
Expand All @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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{}
Expand Down
6 changes: 3 additions & 3 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down