c := context.NewAPIContext(w, r) err := someFunction() if err != nil { c.JSONFailure(http.StatusInternalServerError, "Something went wrong.") return }
c := context.NewAPIContext(w, r) username := c.Session.Get("username") if username == nil { c.JSONFailure(http.StatusUnauthorized, "You must be logged in to access this resource.") return }
c := context.NewAPIContext(w, r) c.Session.SetFlash("message", "Your changes have been saved.") c.JSONSuccess(http.StatusOK, nil)In summary, the github.com/gogits/gogs/modules/context package library provides a simple and convenient APIContext for handling HTTP requests and responses in Go-based web applications.