Upgrade to Pro — share decks privately, control downloads, hide ads and more …

goaを使ったAPI開発/api-development-with-goa

 goaを使ったAPI開発/api-development-with-goa

decafe09

March 25, 2017
Tweet

More Decks by decafe09

Other Decks in Technology

Transcript

  1. var _ = Resource("account", func() { DefaultMedia(Account) BasePath("/accounts") Action("show", func()

    { Routing( GET("/:accountID"), ) Description("Retrieve account with given id.") Params(func() { Param("accountID", Integer, "Account ID", func() { Minimum(1) }) }) Response(OK) Response(NotFound) Response(BadRequest, ErrorMedia) }) } DSLͰͷσβΠϯ
  2. func main() { // Create service service := goa.New("cellar") //

    Mount middleware service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.ErrorHandler(service, true)) service.Use(middleware.Recover()) // Mount "account" controller c := NewAccountController(service) app.MountAccountController(service, c) // Start service if err := service.ListenAndServe(":8081"); err != nil { service.LogError("startup", "err", err) } } ੜ੒͞Εͨίʔυ
  3. func main() { // Create service service := goa.New("cellar") //

    Mount middleware service.Use(myMiddleware.RestrictIP()) service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.ErrorHandler(service, true)) service.Use(middleware.Recover()) // Mount "account" controller c := NewAccountController(service) app.MountAccountController(service, c) // Start service if err := service.ListenAndServe(":8081"); err != nil { service.LogError("startup", "err", err) } } service.Use(myMiddleware.RestrictIP()) ϛυϧ΢ΣΞΛ௥Ճ
  4. func main() { // Create service service := goa.New("cellar") //

    Mount middleware service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.ErrorHandler(service, true)) service.Use(middleware.Recover()) // Mount "account" controller c := NewAccountController(service) app.MountAccountController(service, c) // Start service if err := service.ListenAndServe(":8081"); err != nil { service.LogError("startup", "err", err) } } σβΠϯʹґଘ͠ͳ͍
  5. func main() { // Create service service := goa.New("cellar") //

    Mount middleware service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.ErrorHandler(service, true)) service.Use(middleware.Recover()) // Mount "account" controller c := NewAccountController(service) app.MountAccountController(service, c) // Start service if err := service.ListenAndServe(":8081"); err != nil { service.LogError("startup", "err", err) } } ͜ΕΛ
  6. func main() { // Create service service := goa.New("cellar") //

    Mount middleware mountMiddleware(service) // Mount "account" controller c := NewAccountController(service) app.MountAccountController(service, c) // Start service if err := service.ListenAndServe(":8081"); err != nil { service.LogError("startup", "err", err) } } ͜͏ʂ
  7. ϑΝΠϧΛ෼͚Δ // middleware.go func mountMiddleware(service *goa.Service) { // Put Your

    Code service.Use(middleware.RequestID()) service.Use(middleware.LogRequest(true)) service.Use(middleware.ErrorHandler(service, true)) service.Use(middleware.Recover()) } main.go͔Β੾Γग़ͯ͠ɺผϑΝΠϧʹ͢Δɻ ϛυϧ΢ΣΞ͕૿͑ͯ΋ίʔυੜ੒ͷӨڹΛड͚ͳ͍
  8. swrt https://github.com/decafe09/swrt swagger.jsonͷϧʔςΟϯάΛCLIͰ֬ೝɻ $ swrt -f swagger/swagger.json http://localhost:8081 GET /cellar/_ah/health

    GET /cellar/accounts POST /cellar/accounts GET /cellar/accounts/{accountID} PUT /cellar/accounts/{accountID} DELETE /cellar/accounts/{accountID} GET /cellar/accounts/{accountID}/bottles
  9. goaͷࢀߟαΠτ • ެࣜαΠτ https://goa.design/ja/ ೔ຊޠ൛͋Γ͕ͱ͏͍͟͝·͢ m(_ _)m • goaΛ࢝ΊΑ͏ @ikawaha

    ͞Μ http://ikawaha.hateblo.jp/entry/ 2016/09/11/095129 ͱͯ΋Θ͔Γ΍͍͢Ͱ͢ m(_ _)m