forked from goadesign/plugins
/
view.go
78 lines (71 loc) · 1.98 KB
/
view.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Code generated by goa v2.2.6, DO NOT EDIT.
//
// archiver views
//
// Command:
// $ goa gen goa.design/plugins/goakit/examples/fetcher/archiver/design -o
// $(GOPATH)/src/goa.design/plugins/goakit/examples/fetcher/archiver
package views
import (
goa "goa.design/goa"
)
// ArchiveMedia is the viewed result type that is projected based on a view.
type ArchiveMedia struct {
// Type to project
Projected *ArchiveMediaView
// View to render
View string
}
// ArchiveMediaView is a type that runs validations on a projected type.
type ArchiveMediaView struct {
// The archive resouce href
Href *string
// HTTP status
Status *int
// HTTP response body content
Body *string
}
var (
// ArchiveMediaMap is a map of attribute names in result type ArchiveMedia
// indexed by view name.
ArchiveMediaMap = map[string][]string{
"default": []string{
"href",
"status",
"body",
},
}
)
// ValidateArchiveMedia runs the validations defined on the viewed result type
// ArchiveMedia.
func ValidateArchiveMedia(result *ArchiveMedia) (err error) {
switch result.View {
case "default", "":
err = ValidateArchiveMediaView(result.Projected)
default:
err = goa.InvalidEnumValueError("view", result.View, []interface{}{"default"})
}
return
}
// ValidateArchiveMediaView runs the validations defined on ArchiveMediaView
// using the "default" view.
func ValidateArchiveMediaView(result *ArchiveMediaView) (err error) {
if result.Href == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("href", "result"))
}
if result.Status == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("status", "result"))
}
if result.Body == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("body", "result"))
}
if result.Href != nil {
err = goa.MergeErrors(err, goa.ValidatePattern("result.href", *result.Href, "^/archive/[0-9]+$"))
}
if result.Status != nil {
if *result.Status < 0 {
err = goa.MergeErrors(err, goa.InvalidRangeError("result.status", *result.Status, 0, true))
}
}
return
}