コード例 #1
0
ファイル: controllers.go プロジェクト: derekperkins/gorma
// 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
ファイル: service_test.go プロジェクト: is00hcw/goa
	"net/http"
	"net/url"

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

var _ = Describe("Application", func() {
	const appName = "foo"
	var s goa.Service

	BeforeEach(func() {
		s = goa.New(appName)
		s.SetDecoder(goa.JSONDecoderFactory(), true, "*/*")
		s.SetEncoder(goa.JSONEncoderFactory(), true, "*/*")
	})

	Describe("New", func() {
		It("creates an application", func() {
			Ω(s).ShouldNot(BeNil())
		})

		It("initializes the application fields", func() {
			Ω(s.Name()).Should(Equal(appName))
			Ω(s).Should(BeAssignableToTypeOf(&goa.Application{}))
			app, _ := s.(*goa.Application)
			Ω(app.Name()).Should(Equal(appName))
			Ω(app.Logger).ShouldNot(BeNil())
			Ω(app.ServeMux).ShouldNot(BeNil())
コード例 #3
0
ファイル: controllers.go プロジェクト: derekperkins/gorma
// 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")
}
コード例 #4
0
ファイル: context_test.go プロジェクト: is00hcw/goa
		const appName = "foo"
		var app goa.Service
		const resName = "res"
		const actName = "act"
		var handler, unmarshaler goa.Handler
		const reqBody = `"body"`
		const respStatus = 200
		var respContent = []byte("response")
		var handleFunc goa.HandleFunc
		var rw http.ResponseWriter
		var request *http.Request
		var params url.Values

		BeforeEach(func() {
			app = goa.New(appName)
			app.SetDecoder(goa.JSONDecoderFactory(), true, "*/*")
			app.SetEncoder(goa.JSONEncoderFactory(), true, "*/*")
			handler = func(c *goa.Context) error {
				ctx = c
				c.RespondBytes(respStatus, respContent)
				return nil
			}
			unmarshaler = func(c *goa.Context) error {
				ctx = c
				if req := c.Request(); req != nil {
					var payload interface{}
					err := c.Service().DecodeRequest(ctx, &payload)
					if err != nil {
						return err
					}
					c.SetPayload(payload)