예제 #1
0
// MountAccountController "mounts" a Account resource controller on the given service.
func MountAccountController(service goa.Service, ctrl AccountController) {
	// Setup encoders and decoders. This is idempotent and is done by each MountXXX function.
	tmp15 := goa.GobEncoderFactory()
	service.SetEncoder(tmp15, false, "application/gob", "application/x-gob")
	tmp16 := goa.JSONEncoderFactory()
	service.SetEncoder(tmp16, true, "application/json")
	tmp17 := goa.XMLEncoderFactory()
	service.SetEncoder(tmp17, false, "application/xml", "text/xml")
	tmp18 := goa.GobDecoderFactory()
	service.SetDecoder(tmp18, false, "application/gob", "application/x-gob")
	tmp19 := goa.JSONDecoderFactory()
	service.SetDecoder(tmp19, true, "application/json")
	tmp20 := goa.XMLDecoderFactory()
	service.SetDecoder(tmp20, false, "application/xml", "text/xml")

	// Setup endpoint handler
	var h goa.Handler
	mux := service.ServeMux()
	h = func(c *goa.Context) error {
		ctx, err := NewCreateAccountContext(c)
		ctx.Payload = ctx.RawPayload().(*CreateAccountPayload)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Create(ctx)
	}
	mux.Handle("POST", "/cellar/accounts", ctrl.HandleFunc("Create", h, unmarshalCreateAccountPayload))
	service.Info("mount", "ctrl", "Account", "action", "Create", "route", "POST /cellar/accounts")
	h = func(c *goa.Context) error {
		ctx, err := NewDeleteAccountContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Delete(ctx)
	}
	mux.Handle("DELETE", "/cellar/accounts/:accountID", ctrl.HandleFunc("Delete", h, nil))
	service.Info("mount", "ctrl", "Account", "action", "Delete", "route", "DELETE /cellar/accounts/:accountID")
	h = func(c *goa.Context) error {
		ctx, err := NewShowAccountContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Show(ctx)
	}
	mux.Handle("GET", "/cellar/accounts/:accountID", ctrl.HandleFunc("Show", h, nil))
	service.Info("mount", "ctrl", "Account", "action", "Show", "route", "GET /cellar/accounts/:accountID")
	h = func(c *goa.Context) error {
		ctx, err := NewUpdateAccountContext(c)
		ctx.Payload = ctx.RawPayload().(*UpdateAccountPayload)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Update(ctx)
	}
	mux.Handle("PUT", "/cellar/accounts/:accountID", ctrl.HandleFunc("Update", h, unmarshalUpdateAccountPayload))
	service.Info("mount", "ctrl", "Account", "action", "Update", "route", "PUT /cellar/accounts/:accountID")
}
예제 #2
0
// MountOperandsController "mounts" a Operands resource controller on the given service.
func MountOperandsController(service *goa.Service, ctrl OperandsController) {
	initService(service)
	var h goa.Handler
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewAddOperandsContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Add(rctx)
	}
	service.Mux.Handle("GET", "/add/:left/:right", ctrl.MuxHandler("Add", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Operands"}, goa.KV{"action", "Add"}, goa.KV{"route", "GET /add/:left/:right"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewMultiplyOperandsContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Multiply(rctx)
	}
	service.Mux.Handle("GET", "/multiply/:left/:right", ctrl.MuxHandler("Multiply", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Operands"}, goa.KV{"action", "Multiply"}, goa.KV{"route", "GET /multiply/:left/:right"})
}
예제 #3
0
// MountAuthenticationController "mounts" a Authentication resource controller on the given service.
func MountAuthenticationController(service *goa.Service, ctrl AuthenticationController) {
	initService(service)
	var h goa.Handler
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromFacebookAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromFacebook(rctx)
	}
	service.Mux.Handle("GET", "/FacebookCallback", ctrl.MuxHandler("CallbackResponseFromFacebook", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromFacebook"}, goa.KV{"route", "GET /FacebookCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromGithubAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromGithub(rctx)
	}
	service.Mux.Handle("GET", "/GithubCallback", ctrl.MuxHandler("CallbackResponseFromGithub", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromGithub"}, goa.KV{"route", "GET /GithubCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewCallbackResponseFromGoogleAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.CallbackResponseFromGoogle(rctx)
	}
	service.Mux.Handle("GET", "/GoogleCallback", ctrl.MuxHandler("CallbackResponseFromGoogle", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "CallbackResponseFromGoogle"}, goa.KV{"route", "GET /GoogleCallback"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoFacebookAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoFacebook(rctx)
	}
	service.Mux.Handle("GET", "/FacebookLogin", ctrl.MuxHandler("LogIntoFacebook", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoFacebook"}, goa.KV{"route", "GET /FacebookLogin"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoGithubAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoGithub(rctx)
	}
	service.Mux.Handle("GET", "/GithubLogin", ctrl.MuxHandler("LogIntoGithub", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoGithub"}, goa.KV{"route", "GET /GithubLogin"})
	h = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
		rctx, err := NewLogIntoGoogleAuthenticationContext(ctx)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.LogIntoGoogle(rctx)
	}
	service.Mux.Handle("GET", "/GoogleLogin", ctrl.MuxHandler("LogIntoGoogle", h, nil))
	goa.Info(goa.RootContext, "mount", goa.KV{"ctrl", "Authentication"}, goa.KV{"action", "LogIntoGoogle"}, goa.KV{"route", "GET /GoogleLogin"})
}
예제 #4
0
		Ω(data[1]["title"]).Should(Equal("generic"))
		Ω(data[1]).Should(HaveKey("msg"))
		Ω(data[1]["msg"]).Should(Equal(err2.Error()))
	})
})

var _ = Describe("BadRequestError", func() {
	var rawErr error
	var badReq *goa.BadRequestError

	BeforeEach(func() {
		rawErr = errors.New("raw error")
	})

	JustBeforeEach(func() {
		badReq = goa.NewBadRequestError(rawErr)
	})

	It("builds a bad request error that reports the inner error message", func() {
		Ω(badReq).ShouldNot(BeNil())
		Ω(badReq.Error()).Should(Equal(rawErr.Error()))
	})
})

var _ = Describe("InvalidParamTypeError", func() {
	var valErr, err error
	name := "param"
	val := 42
	expected := "43"

	BeforeEach(func() {
예제 #5
0
// MountBottleController "mounts" a Bottle resource controller on the given service.
func MountBottleController(service goa.Service, ctrl BottleController) {
	// Setup encoders and decoders. This is idempotent and is done by each MountXXX function.
	tmp21 := goa.GobEncoderFactory()
	service.SetEncoder(tmp21, false, "application/gob", "application/x-gob")
	tmp22 := goa.JSONEncoderFactory()
	service.SetEncoder(tmp22, true, "application/json")
	tmp23 := goa.XMLEncoderFactory()
	service.SetEncoder(tmp23, false, "application/xml", "text/xml")
	tmp24 := goa.GobDecoderFactory()
	service.SetDecoder(tmp24, false, "application/gob", "application/x-gob")
	tmp25 := goa.JSONDecoderFactory()
	service.SetDecoder(tmp25, true, "application/json")
	tmp26 := goa.XMLDecoderFactory()
	service.SetDecoder(tmp26, false, "application/xml", "text/xml")

	// Setup endpoint handler
	var h goa.Handler
	mux := service.ServeMux()
	h = func(c *goa.Context) error {
		ctx, err := NewCreateBottleContext(c)
		ctx.Payload = ctx.RawPayload().(*CreateBottlePayload)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Create(ctx)
	}
	mux.Handle("POST", "/cellar/accounts/:accountID/bottles", ctrl.HandleFunc("Create", h, unmarshalCreateBottlePayload))
	service.Info("mount", "ctrl", "Bottle", "action", "Create", "route", "POST /cellar/accounts/:accountID/bottles")
	h = func(c *goa.Context) error {
		ctx, err := NewDeleteBottleContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Delete(ctx)
	}
	mux.Handle("DELETE", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Delete", h, nil))
	service.Info("mount", "ctrl", "Bottle", "action", "Delete", "route", "DELETE /cellar/accounts/:accountID/bottles/:bottleID")
	h = func(c *goa.Context) error {
		ctx, err := NewListBottleContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.List(ctx)
	}
	mux.Handle("GET", "/cellar/accounts/:accountID/bottles", ctrl.HandleFunc("List", h, nil))
	service.Info("mount", "ctrl", "Bottle", "action", "List", "route", "GET /cellar/accounts/:accountID/bottles")
	h = func(c *goa.Context) error {
		ctx, err := NewRateBottleContext(c)
		ctx.Payload = ctx.RawPayload().(*RateBottlePayload)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Rate(ctx)
	}
	mux.Handle("PUT", "/cellar/accounts/:accountID/bottles/:bottleID/actions/rate", ctrl.HandleFunc("Rate", h, unmarshalRateBottlePayload))
	service.Info("mount", "ctrl", "Bottle", "action", "Rate", "route", "PUT /cellar/accounts/:accountID/bottles/:bottleID/actions/rate")
	h = func(c *goa.Context) error {
		ctx, err := NewShowBottleContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Show(ctx)
	}
	mux.Handle("GET", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Show", h, nil))
	service.Info("mount", "ctrl", "Bottle", "action", "Show", "route", "GET /cellar/accounts/:accountID/bottles/:bottleID")
	h = func(c *goa.Context) error {
		ctx, err := NewUpdateBottleContext(c)
		ctx.Payload = ctx.RawPayload().(*UpdateBottlePayload)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Update(ctx)
	}
	mux.Handle("PATCH", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Update", h, unmarshalUpdateBottlePayload))
	service.Info("mount", "ctrl", "Bottle", "action", "Update", "route", "PATCH /cellar/accounts/:accountID/bottles/:bottleID")
}