func NewError(status int, msg string) *Error { return &Error{status, errors.New(msg)} } // Example usage: err := NewError(http.StatusInternalServerError, "Internal Server Error")
func IsErrNotExist(err error) bool { if e, ok := err.(*Error); ok { if e.Status == http.StatusNotFound { return true } } return false } // Example usage: if IsErrNotExist(err) { // handle "Not Found" error }
func (ctx *Context) Render(status int, name string, data interface{}, htmlOpt ...RenderOptions) { // ... if err, ok := data.(error); ok { ctx.Data["Err"] = err } // ... } // Example usage: ctx.Render(http.StatusInternalServerError, "500", NewError(http.StatusInternalServerError, "Internal Server Error"))Overall, the `Context Error` package library is a useful tool for handling errors in a web application built with Gogs.