-
Notifications
You must be signed in to change notification settings - Fork 0
/
contexts.go
61 lines (55 loc) · 1.78 KB
/
contexts.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Code generated by goagen v1.3.1, DO NOT EDIT.
//
// API "cellar": Application Contexts
//
// Command:
// $ goagen
// --design=github.com/nikhil-thomas/technik-dojo/goa-exp/goa-exp-1/design
// --out=$(GOPATH)/src/github.com/nikhil-thomas/technik-dojo/goa-exp/goa-exp-1
// --version=v1.3.1
package app
import (
"context"
"github.com/goadesign/goa"
"net/http"
"strconv"
)
// ShowBottleContext provides the bottle show action context.
type ShowBottleContext struct {
context.Context
*goa.ResponseData
*goa.RequestData
BottleID int
}
// NewShowBottleContext parses the incoming request URL and body, performs validations and creates the
// context used by the bottle controller show action.
func NewShowBottleContext(ctx context.Context, r *http.Request, service *goa.Service) (*ShowBottleContext, error) {
var err error
resp := goa.ContextResponse(ctx)
resp.Service = service
req := goa.ContextRequest(ctx)
req.Request = r
rctx := ShowBottleContext{Context: ctx, ResponseData: resp, RequestData: req}
paramBottleID := req.Params["bottleID"]
if len(paramBottleID) > 0 {
rawBottleID := paramBottleID[0]
if bottleID, err2 := strconv.Atoi(rawBottleID); err2 == nil {
rctx.BottleID = bottleID
} else {
err = goa.MergeErrors(err, goa.InvalidParamTypeError("bottleID", rawBottleID, "integer"))
}
}
return &rctx, err
}
// OK sends a HTTP response with status code 200.
func (ctx *ShowBottleContext) OK(r *GoaExampleBottle) error {
if ctx.ResponseData.Header().Get("Content-Type") == "" {
ctx.ResponseData.Header().Set("Content-Type", "application/vnd.goa.example.bottle+json")
}
return ctx.ResponseData.Service.Send(ctx.Context, 200, r)
}
// NotFound sends a HTTP response with status code 404.
func (ctx *ShowBottleContext) NotFound() error {
ctx.ResponseData.WriteHeader(404)
return nil
}