func Image(ctx *tango.Context) { token := ctx.Params().Get(":path") // split token and file ext var filePath string if i := strings.IndexRune(token, '.'); i == -1 { return } else { filePath = token[i+1:] token = token[:i] } // decode token to file path var image models.Image if err := image.DecodeToken(token); err != nil { log.Info(err) return } // file real path filePath = attachment.GenImagePath(&image) + filePath // if x-send on then set header and http status // fall back use proxy serve file if setting.ImageXSend { //ext := filepath.Ext(filePath) // TODO: //ctx.Header().ContentType(ext) ctx.Header().Set(setting.ImageXSendHeader, "/"+filePath) ctx.WriteHeader(http.StatusOK) } else { // direct serve file use go ctx.ServeFile(filePath) } }
func (rh *RecoveryHandler) Handle(ctx *tango.Context) { // capture render-controller error if render, ok := ctx.Action().(ITheme); ok { if err, ok := ctx.Result.(tango.AbortError); ok { render.RenderError(err.Code(), err) return } if err, ok := ctx.Result.(error); ok { ctx.WriteHeader(500) render.RenderError(ctx.Status(), err) return } } // capture abort error /* if err, ok := ctx.Result.(tango.AbortError); ok { ctx.WriteHeader(err.Code()) theme := new(ThemeRender) theme.SetTheme(nil) theme.RenderError(err.Code(), err) return }*/ // unexpected error tango.Errors()(ctx) }