/
service.go
116 lines (101 loc) · 3.18 KB
/
service.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Code generated by goa v2.2.6, DO NOT EDIT.
//
// archiver service
//
// Command:
// $ goa gen goa.design/plugins/goakit/examples/fetcher/archiver/design -o
// $(GOPATH)/src/goa.design/plugins/goakit/examples/fetcher/archiver
package archiver
import (
"context"
"goa.design/goa"
archiverviews "goa.design/plugins/goakit/examples/fetcher/archiver/gen/archiver/views"
)
// Service is the archiver service interface.
type Service interface {
// Archive HTTP response
Archive(context.Context, *ArchivePayload) (res *ArchiveMedia, err error)
// Read HTTP response from archive
Read(context.Context, *ReadPayload) (res *ArchiveMedia, err error)
}
// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = "archiver"
// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
var MethodNames = [2]string{"archive", "read"}
// ArchivePayload is the payload type of the archiver service archive method.
type ArchivePayload struct {
// HTTP status
Status int
// HTTP response body content
Body string
}
// ArchiveMedia is the result type of the archiver service archive method.
type ArchiveMedia struct {
// The archive resouce href
Href string
// HTTP status
Status int
// HTTP response body content
Body string
}
// ReadPayload is the payload type of the archiver service read method.
type ReadPayload struct {
// ID of archive
ID int
}
// MakeNotFound builds a goa.ServiceError from an error.
func MakeNotFound(err error) *goa.ServiceError {
return &goa.ServiceError{
Name: "not_found",
ID: goa.NewErrorID(),
Message: err.Error(),
}
}
// MakeBadRequest builds a goa.ServiceError from an error.
func MakeBadRequest(err error) *goa.ServiceError {
return &goa.ServiceError{
Name: "bad_request",
ID: goa.NewErrorID(),
Message: err.Error(),
}
}
// NewArchiveMedia initializes result type ArchiveMedia from viewed result type
// ArchiveMedia.
func NewArchiveMedia(vres *archiverviews.ArchiveMedia) *ArchiveMedia {
return newArchiveMedia(vres.Projected)
}
// NewViewedArchiveMedia initializes viewed result type ArchiveMedia from
// result type ArchiveMedia using the given view.
func NewViewedArchiveMedia(res *ArchiveMedia, view string) *archiverviews.ArchiveMedia {
p := newArchiveMediaView(res)
return &archiverviews.ArchiveMedia{Projected: p, View: "default"}
}
// newArchiveMedia converts projected type ArchiveMedia to service type
// ArchiveMedia.
func newArchiveMedia(vres *archiverviews.ArchiveMediaView) *ArchiveMedia {
res := &ArchiveMedia{}
if vres.Href != nil {
res.Href = *vres.Href
}
if vres.Status != nil {
res.Status = *vres.Status
}
if vres.Body != nil {
res.Body = *vres.Body
}
return res
}
// newArchiveMediaView projects result type ArchiveMedia to projected type
// ArchiveMediaView using the "default" view.
func newArchiveMediaView(res *ArchiveMedia) *archiverviews.ArchiveMediaView {
vres := &archiverviews.ArchiveMediaView{
Href: &res.Href,
Status: &res.Status,
Body: &res.Body,
}
return vres
}