本文整理汇总了Golang中github.com/astaxie/beego/middleware.ShowErr函数的典型用法代码示例。如果您正苦于以下问题:Golang ShowErr函数的具体用法?Golang ShowErr怎么用?Golang ShowErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShowErr函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: recoverPanic
func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Request) {
if err := recover(); err != nil {
if err == USERSTOPRUN {
return
}
if _, ok := err.(middleware.HTTPException); ok {
// catch intented errors, only for HTTP 4XX and 5XX
} else {
if RunMode == "dev" {
if !RecoverPanic {
panic(err)
} else {
if ErrorsShow {
if handler, ok := middleware.ErrorMaps[fmt.Sprint(err)]; ok {
handler(rw, r)
return
}
}
var stack string
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
stack = stack + fmt.Sprintln(file, line)
}
middleware.ShowErr(err, rw, r, stack)
}
} else {
if !RecoverPanic {
panic(err)
} else {
// in production model show all infomation
if ErrorsShow {
handler := p.getErrorHandler(fmt.Sprint(err))
handler(rw, r)
return
} else {
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
}
}
}
}
}
}
}
开发者ID:4eek,项目名称:beego,代码行数:57,代码来源:router.go
示例2: ServeHTTP
// Implement http.Handler interface.
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
if err == USERSTOPRUN {
return
}
if _, ok := err.(middleware.HTTPException); ok {
// catch intented errors, only for HTTP 4XX and 5XX
} else {
if RunMode == "dev" {
if !RecoverPanic {
panic(err)
} else {
if ErrorsShow {
if handler, ok := middleware.ErrorMaps[fmt.Sprint(err)]; ok {
handler(rw, r)
return
}
}
var stack string
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
stack = stack + fmt.Sprintln(file, line)
}
middleware.ShowErr(err, rw, r, stack)
}
} else {
if !RecoverPanic {
panic(err)
} else {
// in production model show all infomation
if ErrorsShow {
handler := p.getErrorHandler(fmt.Sprint(err))
handler(rw, r)
return
} else {
Critical("the request url is ", r.URL.Path)
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
}
}
}
}
}
}
}()
starttime := time.Now()
requestPath := r.URL.Path
var runrouter reflect.Type
var findrouter bool
var runMethod string
params := make(map[string]string)
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
// init context
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
}
// defined filter function
do_filter := func(pos int) (started bool) {
if p.enableFilter {
if l, ok := p.filters[pos]; ok {
for _, filterR := range l {
if ok, p := filterR.ValidRouter(r.URL.Path); ok {
context.Input.Params = p
filterR.filterFunc(context)
if w.started {
return true
}
}
}
}
}
//.........这里部分代码省略.........
开发者ID:jrodriguezjr,项目名称:beego,代码行数:101,代码来源:router.go
示例3: ServeHTTP
// AutoRoute
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
errstr := fmt.Sprint(err)
if handler, ok := middleware.ErrorMaps[errstr]; ok && ErrorsShow {
handler(rw, r)
} else {
if !RecoverPanic {
// go back to panic
panic(err)
} else {
var stack string
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
if RunMode == "dev" {
stack = stack + fmt.Sprintln(file, line)
}
}
if RunMode == "dev" {
middleware.ShowErr(err, rw, r, stack)
}
}
}
}
}()
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(w),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
context.Output = beecontext.NewOutput(rw)
}
if SessionOn {
context.Input.CruSession = GlobalSessions.SessionStart(w, r)
}
var runrouter *controllerInfo
var findrouter bool
params := make(map[string]string)
if p.enableFilter {
if l, ok := p.filters["BeforRouter"]; ok {
for _, filterR := range l {
if filterR.ValidRouter(r.URL.Path) {
filterR.filterFunc(context)
if w.started {
return
}
}
}
}
}
//static file server
for prefix, staticDir := range StaticDir {
if r.URL.Path == "/favicon.ico" {
file := staticDir + r.URL.Path
http.ServeFile(w, r, file)
w.started = true
return
}
if strings.HasPrefix(r.URL.Path, prefix) {
file := staticDir + r.URL.Path[len(prefix):]
finfo, err := os.Stat(file)
if err != nil {
return
}
//if the request is dir and DirectoryIndex is false then
if finfo.IsDir() && !DirectoryIndex {
middleware.Exception("403", rw, r, "403 Forbidden")
return
}
http.ServeFile(w, r, file)
w.started = true
return
}
}
if p.enableFilter {
if l, ok := p.filters["AfterStatic"]; ok {
for _, filterR := range l {
if filterR.ValidRouter(r.URL.Path) {
filterR.filterFunc(context)
//.........这里部分代码省略.........
开发者ID:rose312,项目名称:beego,代码行数:101,代码来源:router.go
示例4: ServeHTTP
// AutoRoute
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
if _, ok := err.(middleware.HTTPException); ok {
// catch intented errors, only for HTTP 4XX and 5XX
} else {
if RunMode == "dev" {
if !RecoverPanic {
panic(err)
} else {
var stack string
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
stack = stack + fmt.Sprintln(file, line)
}
middleware.ShowErr(err, rw, r, stack)
}
} else {
if ErrorsShow {
handler := p.getErrorHandler(fmt.Sprint(err))
handler(rw, r)
} else {
if !RecoverPanic {
panic(err)
} else {
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
}
}
}
}
}
}
}()
starttime := time.Now()
requestPath := r.URL.Path
var runrouter *controllerInfo
var findrouter bool
params := make(map[string]string)
w := &responseWriter{writer: rw}
w.Header().Set("Server", BeegoServerName)
context := &beecontext.Context{
ResponseWriter: w,
Request: r,
Input: beecontext.NewInput(r),
Output: beecontext.NewOutput(w),
}
context.Output.Context = context
context.Output.EnableGzip = EnableGzip
do_filter := func(pos int) (started bool) {
if p.enableFilter {
if l, ok := p.filters[pos]; ok {
for _, filterR := range l {
if ok, p := filterR.ValidRouter(r.URL.Path); ok {
context.Input.Params = p
filterR.filterFunc(context)
if w.started {
return true
}
}
}
}
}
return false
}
if context.Input.IsWebsocket() {
context.ResponseWriter = rw
context.Output = beecontext.NewOutput(rw)
}
if !utils.InSlice(strings.ToLower(r.Method), HTTPMETHOD) {
http.Error(w, "Method Not Allowed", 405)
goto Admin
}
if do_filter(BeforeRouter) {
goto Admin
}
//static file server
for prefix, staticDir := range StaticDir {
if r.URL.Path == "/favicon.ico" {
file := staticDir + r.URL.Path
//.........这里部分代码省略.........
开发者ID:peilongwu,项目名称:beego,代码行数:101,代码来源:router.go
注:本文中的github.com/astaxie/beego/middleware.ShowErr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论