当前位置: 首页>>代码示例>>Golang>>正文


Golang goa.Service类代码示例

本文整理汇总了Golang中github.com/raphael/goa.Service的典型用法代码示例。如果您正苦于以下问题:Golang Service类的具体用法?Golang Service怎么用?Golang Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MountPreflightController

// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
	router := service.HTTPHandler().(*httprouter.Router)
	for _, res := range spec {
		path := res.Path
		if res.IsPathPrefix {
			if strings.HasSuffix(path, "/") {
				path += "*cors"
			} else {
				path += "/*cors"
			}
		}
		var handle httprouter.Handle
		handle, _, tsr := router.Lookup("OPTIONS", path)
		if tsr {
			if strings.HasSuffix(path, "/") {
				path = path[:len(path)-1]
			} else {
				path = path + "/"
			}
			handle, _, _ = router.Lookup("OPTIONS", path)
		}
		if handle == nil {
			h := func(ctx *goa.Context) error {
				return ctx.Respond(200, nil)
			}
			router.OPTIONS(path, goa.NewHTTPRouterHandle(service, "CORS", "preflight", h))
		}
	}
}
开发者ID:patrickToca,项目名称:goa,代码行数:30,代码来源:middleware.go

示例2: MountAccountController

// MountAccountController "mounts" a Account resource controller on the given service.
func MountAccountController(service goa.Service, ctrl AccountController) {
	router := service.HTTPHandler().(*httprouter.Router)
	var h goa.Handler
	h = func(c *goa.Context) error {
		ctx, err := NewCreateAccountContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Create(ctx)
	}
	router.Handle("POST", "/cellar/accounts", goa.NewHTTPRouterHandle(service, "Account", "Create", h))
	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)
	}
	router.Handle("DELETE", "/cellar/accounts/:accountID", goa.NewHTTPRouterHandle(service, "Account", "Delete", h))
	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)
	}
	router.Handle("GET", "/cellar/accounts/:accountID", goa.NewHTTPRouterHandle(service, "Account", "Show", h))
	service.Info("mount", "ctrl", "Account", "action", "Show", "route", "GET /cellar/accounts/:accountID")
	h = func(c *goa.Context) error {
		ctx, err := NewUpdateAccountContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Update(ctx)
	}
	router.Handle("PUT", "/cellar/accounts/:accountID", goa.NewHTTPRouterHandle(service, "Account", "Update", h))
	service.Info("mount", "ctrl", "Account", "action", "Update", "route", "PUT /cellar/accounts/:accountID")
}
开发者ID:patrickToca,项目名称:goa,代码行数:41,代码来源:controllers.go

示例3: MountSeriesController

// MountSeriesController "mounts" a Series resource controller on the given service.
func MountSeriesController(service goa.Service, ctrl SeriesController) {
	router := service.HTTPHandler().(*httprouter.Router)
	var h goa.Handler
	h = func(c *goa.Context) error {
		ctx, err := NewCreateSeriesContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Create(ctx)
	}
	router.Handle("POST", "/congo/accounts/:accountID/series", goa.NewHTTPRouterHandle(service, "Series", "Create", h))
	service.Info("mount", "ctrl", "Series", "action", "Create", "route", "POST /congo/accounts/:accountID/series")
	h = func(c *goa.Context) error {
		ctx, err := NewListSeriesContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.List(ctx)
	}
	router.Handle("GET", "/congo/accounts/:accountID/series", goa.NewHTTPRouterHandle(service, "Series", "List", h))
	service.Info("mount", "ctrl", "Series", "action", "List", "route", "GET /congo/accounts/:accountID/series")
	h = func(c *goa.Context) error {
		ctx, err := NewShowSeriesContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Show(ctx)
	}
	router.Handle("GET", "/congo/accounts/:accountID/series/:seriesID", goa.NewHTTPRouterHandle(service, "Series", "Show", h))
	service.Info("mount", "ctrl", "Series", "action", "Show", "route", "GET /congo/accounts/:accountID/series/:seriesID")
	h = func(c *goa.Context) error {
		ctx, err := NewUpdateSeriesContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Update(ctx)
	}
	router.Handle("PATCH", "/congo/accounts/:accountID/series/:seriesID", goa.NewHTTPRouterHandle(service, "Series", "Update", h))
	service.Info("mount", "ctrl", "Series", "action", "Update", "route", "PATCH /congo/accounts/:accountID/series/:seriesID")
}
开发者ID:AidHamza,项目名称:congo,代码行数:41,代码来源:controllers.go

示例4: MountPreflightController

// MountPreflightController mounts the handlers for the CORS preflight requests onto service.
func MountPreflightController(service goa.Service, spec Specification) {
	for _, res := range spec {
		path := res.Path
		if res.IsPathPrefix {
			if strings.HasSuffix(path, "/") {
				path += "*cors"
			} else {
				path += "/*cors"
			}
		}
		handle := service.ServeMux().Lookup("OPTIONS", path)
		if handle == nil {
			h := func(ctx *goa.Context) error {
				return ctx.Respond(200, nil)
			}
			ctrl := service.NewController("cors")
			service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("preflight", h))
		}
	}
}
开发者ID:tylerb,项目名称:goa-middleware,代码行数:21,代码来源:middleware.go

示例5: NewAccountController

// NewAccountController creates a account controller.
func NewAccountController(service goa.Service) AccountController {
	return &AccountController{Controller: service.NewController("AccountController")}
}
开发者ID:MathieuDoyon,项目名称:goa-test,代码行数:4,代码来源:account.go

示例6: MountController

// MountController mounts the JavaScript example controller under "/js".
func MountController(service goa.Service) {
	// Serve static files under js
	service.ServeFiles("/js/*filepath", "/home/raphael/go/src/github.com/raphael/goa/examples/cellar/js")
	service.Info("mount", "ctrl", "JS", "action", "ServeFiles", "route", "GET /js/*")
}
开发者ID:tylerb,项目名称:goa,代码行数:6,代码来源:example.go

示例7: NewBottleController

// NewBottleController creates a bottle controller.
func NewBottleController(service goa.Service) BottleController {
	return &BottleController{Controller: service.NewController("BottleController")}
}
开发者ID:MathieuDoyon,项目名称:goa-test,代码行数:4,代码来源:bottle.go

示例8: MountController

// MountController mounts the swagger spec controller under "/swagger.json".
func MountController(service goa.Service) {
	service.Info("mount", "ctrl", "Swagger", "action", "Show", "route", "GET /swagger.json")
	h := goa.NewHTTPRouterHandle(service, "Swagger", "Show", getSwagger)
	service.HTTPHandler().(*httprouter.Router).Handle("GET", "/swagger.json", h)
}
开发者ID:patrickToca,项目名称:goa,代码行数:6,代码来源:swagger.go

示例9:

	Describe("GetMany", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.GetMany("foo")).Should(BeNil())
		})
	})

	Describe("Payload", func() {
		It("returns nil if not initialized", func() {
			Ω(ctx.Payload()).Should(BeNil())
		})
	})

	Context("with a request response", func() {
		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)
			handler = func(c *goa.Context) error {
				ctx = c
开发者ID:yonglehou,项目名称:goa,代码行数:30,代码来源:context_test.go

示例10:

package goa_test

import (
	"fmt"
	"net/http"

	"github.com/julienschmidt/httprouter"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/raphael/goa"
)

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

	BeforeEach(func() {
		s = goa.New(appName)
	})

	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())
开发者ID:harboe,项目名称:goa,代码行数:31,代码来源:service_test.go

示例11: MountController

// MountController mounts the API JSON schema controller under "/schema.json".
func MountController(service goa.Service) {
	service.ServeFiles("/schema.json", "schema/schema.json")
}
开发者ID:tylerb,项目名称:goa,代码行数:4,代码来源:schema.go

示例12: NewBottle

// NewBottle creates a bottle controller.
func NewBottle(service goa.Service) *BottleController {
	return &BottleController{
		Controller: service.NewController("Bottle"),
		db:         NewDB(),
	}
}
开发者ID:tylerb,项目名称:goa,代码行数:7,代码来源:bottle.go

示例13: NewAccount

// NewAccount creates a account controller.
func NewAccount(service goa.Service) *AccountController {
	return &AccountController{
		Controller: service.NewController("Account"),
		db:         NewDB(),
	}
}
开发者ID:tylerb,项目名称:goa,代码行数:7,代码来源:account.go

示例14: MountController

// MountController mounts the swagger spec controller under "/swagger.json".
func MountController(service goa.Service) {
	service.ServeFiles("/swagger.json", "swagger/swagger.json")
}
开发者ID:tylerb,项目名称:goa,代码行数:4,代码来源:swagger.go

示例15: MountBottleController

// MountBottleController "mounts" a Bottle resource controller on the given service.
func MountBottleController(service goa.Service, ctrl BottleController) {
	var h goa.Handler
	mux := service.ServeMux()
	h = func(c *goa.Context) error {
		ctx, err := NewCreateBottleContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Create(ctx)
	}
	mux.Handle("POST", "/cellar/accounts/:accountID/bottles", ctrl.HandleFunc("Create", h))
	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))
	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))
	service.Info("mount", "ctrl", "Bottle", "action", "List", "route", "GET /cellar/accounts/:accountID/bottles")
	h = func(c *goa.Context) error {
		ctx, err := NewRateBottleContext(c)
		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))
	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))
	service.Info("mount", "ctrl", "Bottle", "action", "Show", "route", "GET /cellar/accounts/:accountID/bottles/:bottleID")
	h = func(c *goa.Context) error {
		ctx, err := NewUpdateBottleContext(c)
		if err != nil {
			return goa.NewBadRequestError(err)
		}
		return ctrl.Update(ctx)
	}
	mux.Handle("PATCH", "/cellar/accounts/:accountID/bottles/:bottleID", ctrl.HandleFunc("Update", h))
	service.Info("mount", "ctrl", "Bottle", "action", "Update", "route", "PATCH /cellar/accounts/:accountID/bottles/:bottleID")
}
开发者ID:tylerb,项目名称:goa,代码行数:59,代码来源:controllers.go


注:本文中的github.com/raphael/goa.Service类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。