本文整理匯總了Golang中github.com/labstack/echo.Context.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Error方法的具體用法?Golang Context.Error怎麽用?Golang Context.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.Error方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: errorHandler
// errorHandler will catch all errors returned from handlers and convert them
// into a JSON response. If the error is not from the type HTTPError an internal
// server error will follow.
func errorHandler(err error, c *echo.Context) {
if httpError, ok := err.(handler.HTTPError); ok {
c.JSON(httpError.Code, httpError)
return
}
c.Error(errors.New("internal server error"))
}
示例2: JobsNewPost
// JobsNewPost process the new job form.
//
// Method POST
//
// Route /dash/jobs/new
//
// Restrictions Yes
//
// Template None
func JobsNewPost(ctx *echo.Context) error {
var flashMessages = flash.New()
f := forms.New(utils.GetLang(ctx))
jf := f.JobForm()(ctx.Request())
if !jf.IsValid() {
// TODO: improve flash message ?
flashMessages.Err(msgInvalidorm)
flashMessages.Save(ctx)
ctx.Redirect(http.StatusFound, "/dash/jobs/new")
return nil
}
if isLoged := ctx.Get("IsLoged"); isLoged != nil {
person := ctx.Get("User").(*models.Person)
if jerr := query.PersonCreateJob(person, jf.GetModel().(forms.JobForm)); jerr != nil {
// TODO: improve flash message ?
flashMessages.Err("some really bad fish happened")
flashMessages.Save(ctx)
ctx.Redirect(http.StatusFound, "/dash/jobs/new")
return nil
}
// add flash message
flashMessages.Success("new job was created successful")
flashMessages.Save(ctx)
ctx.Redirect(http.StatusFound, "/dash/")
return nil
}
he := echo.NewHTTPError(http.StatusUnauthorized)
ctx.Error(he)
return nil
}
示例3: Default
// shortcut to get session
func Default(c echo.Context) Session {
ses, ok := c.Get(DefaultKey).(Session)
if !ok {
c.Error(ErrDefaultSessionMiddlewareNotRegistered)
}
return ses
}