Giter Site home page Giter Site logo

Comments (5)

unknwon avatar unknwon commented on August 15, 2024

ErrorHandler 是用来直接响应 error 的,不是用来返回 error 类型的,否则就不叫 Handler 了。

from binding.

cgyy avatar cgyy commented on August 15, 2024

你好,没写明白,我的意思是这样:
想在自定义的错误中这样处理: 在flash中显示错误消息,并调转到其他页面:

func (cf ContactForm) Error(ctx *macaron.Context, errs binding.Errors) {
   flash.Error("表单填写不完整") // 目前的方法签名不能实现这样的功能
   ctx.Redirect("/")
}

是否方法签名可以是这样

       //binding.go 第641行
    ErrorHandler interface {
        // Error handles validation errors with custom process.
        Error(...interface{})
    }

```go

这样一来,自定义的错误处理就可以使用其他参数了


from binding.

unknwon avatar unknwon commented on August 15, 2024

你可以使用以下代码手工获得注入的服务:

flash := m.GetVal(reflect.TypeOf(&session.Flash{})).Interface().(*session.Flash)

from binding.

cgyy avatar cgyy commented on August 15, 2024

你好,这样可以了

flash := ctx.GetVal(reflect.TypeOf(&session.Flash{})).Interface().(*session.Flash)

谢谢!

from binding.

unknwon avatar unknwon commented on August 15, 2024

好的~

from binding.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.