forked from dikhan/terraform-provider-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottle.go
46 lines (40 loc) · 1.18 KB
/
bottle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"github.com/dikhan/terraform-provider-openapi/examples/goa/api/app"
"github.com/goadesign/goa"
"github.com/hashicorp/go-uuid"
)
var db = map[string]*app.Bottle{}
// BottleController implements the bottle resource.
type BottleController struct {
*goa.Controller
}
// NewBottleController creates a bottle controller.
func NewBottleController(service *goa.Service) *BottleController {
return &BottleController{Controller: service.NewController("BottleController")}
}
// Create runs the create action.
func (c *BottleController) Create(ctx *app.CreateBottleContext) error {
// BottleController_Create: start_implement
// Put your logic here
id, _ := uuid.GenerateUUID()
response := &app.Bottle{
ID: id,
Rating: ctx.Payload.Rating,
Name: ctx.Payload.Name,
Vintage: ctx.Payload.Vintage,
}
db[id] = response
return ctx.Created(response)
// BottleController_Create: end_implement
}
// Show runs the show action.
func (c *BottleController) Show(ctx *app.ShowBottleContext) error {
// BottleController_Show: start_implement
// Put your logic here
if db[ctx.ID] == nil {
return ctx.NotFound()
}
return ctx.OK(db[ctx.ID])
// BottleController_Show: end_implement
}