Exemplo n.º 1
0
func TErrorHandler(witness *bool) goa.Middleware {
	m, _ := goa.NewMiddleware(func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		*witness = true
		return nil
	})
	return m
}
Exemplo n.º 2
0
// New creates a static username/password auth middleware.
//
// Example:
//    app.UseBasicAuth(basicauth.New("admin", "password"))
//
// It doesn't get simpler than that.
//
// If you want to handle the username and password checks dynamically,
// copy the source of `New`, it's 8 lines and you can tweak at will.
func New(username, password string) goa.Middleware {
	middleware, _ := goa.NewMiddleware(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		u, p, ok := r.BasicAuth()
		if !ok || u != username || p != password {
			return ErrBasicAuthFailed("Authentication failed")
		}
		return nil
	})
	return middleware
}
Exemplo n.º 3
0
	"gopkg.in/inconshreveable/log15.v2"

	"github.com/goadesign/goa"
	"github.com/goadesign/middleware"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("NewMiddleware", func() {
	var input interface{}
	var middleware goa.Middleware
	var mErr error

	JustBeforeEach(func() {
		middleware, mErr = goa.NewMiddleware(input)
	})

	Context("using a goa Middleware", func() {
		var goaMiddleware goa.Middleware

		BeforeEach(func() {
			goaMiddleware = func(h goa.Handler) goa.Handler { return h }
			input = goaMiddleware
		})

		It("returns the middleware", func() {
			Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goaMiddleware)))
			Ω(mErr).ShouldNot(HaveOccurred())
		})
	})