-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathservice.go
178 lines (155 loc) · 5.33 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Code generated by goa v3.15.2, DO NOT EDIT.
//
// tools service
//
// Command:
// $ goa gen github.com/arduino/arduino-create-agent/design
package tools
import (
"context"
toolsviews "github.com/arduino/arduino-create-agent/gen/tools/views"
goa "goa.design/goa/v3/pkg"
)
// The tools service manages the available and installed tools
type Service interface {
// Available implements available.
Available(context.Context) (res ToolCollection, err error)
// Installedhead implements installedhead.
Installedhead(context.Context) (err error)
// Installed implements installed.
Installed(context.Context) (res ToolCollection, err error)
// Install implements install.
Install(context.Context, *ToolPayload) (res *Operation, err error)
// Remove implements remove.
Remove(context.Context, *ToolPayload) (res *Operation, err error)
}
// APIName is the name of the API as defined in the design.
const APIName = "arduino-create-agent"
// APIVersion is the version of the API as defined in the design.
const APIVersion = "0.0.1"
// 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 = "tools"
// 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 = [5]string{"available", "installedhead", "installed", "install", "remove"}
// Operation is the result type of the tools service install method.
type Operation struct {
// The status of the operation
Status string
}
// A tool is an executable program that can upload sketches.
type Tool struct {
// The name of the tool
Name string
// The version of the tool
Version string
// The packager of the tool
Packager string
}
// ToolCollection is the result type of the tools service available method.
type ToolCollection []*Tool
// ToolPayload is the payload type of the tools service install method.
type ToolPayload struct {
// The name of the tool
Name string
// The version of the tool
Version string
// The packager of the tool
Packager string
// The url where the package can be found. Optional.
// If present checksum must also be present.
URL *string
// A checksum of the archive. Mandatory when url is present.
// This ensures that the package is downloaded correcly.
Checksum *string
// The signature used to sign the url. Mandatory when url is present.
// This ensure the security of the file downloaded
Signature *string
}
// MakeNotFound builds a goa.ServiceError from an error.
func MakeNotFound(err error) *goa.ServiceError {
return goa.NewServiceError(err, "not_found", false, false, false)
}
// NewToolCollection initializes result type ToolCollection from viewed result
// type ToolCollection.
func NewToolCollection(vres toolsviews.ToolCollection) ToolCollection {
return newToolCollection(vres.Projected)
}
// NewViewedToolCollection initializes viewed result type ToolCollection from
// result type ToolCollection using the given view.
func NewViewedToolCollection(res ToolCollection, view string) toolsviews.ToolCollection {
p := newToolCollectionView(res)
return toolsviews.ToolCollection{Projected: p, View: "default"}
}
// NewOperation initializes result type Operation from viewed result type
// Operation.
func NewOperation(vres *toolsviews.Operation) *Operation {
return newOperation(vres.Projected)
}
// NewViewedOperation initializes viewed result type Operation from result type
// Operation using the given view.
func NewViewedOperation(res *Operation, view string) *toolsviews.Operation {
p := newOperationView(res)
return &toolsviews.Operation{Projected: p, View: "default"}
}
// newToolCollection converts projected type ToolCollection to service type
// ToolCollection.
func newToolCollection(vres toolsviews.ToolCollectionView) ToolCollection {
res := make(ToolCollection, len(vres))
for i, n := range vres {
res[i] = newTool(n)
}
return res
}
// newToolCollectionView projects result type ToolCollection to projected type
// ToolCollectionView using the "default" view.
func newToolCollectionView(res ToolCollection) toolsviews.ToolCollectionView {
vres := make(toolsviews.ToolCollectionView, len(res))
for i, n := range res {
vres[i] = newToolView(n)
}
return vres
}
// newTool converts projected type Tool to service type Tool.
func newTool(vres *toolsviews.ToolView) *Tool {
res := &Tool{}
if vres.Name != nil {
res.Name = *vres.Name
}
if vres.Version != nil {
res.Version = *vres.Version
}
if vres.Packager != nil {
res.Packager = *vres.Packager
}
return res
}
// newToolView projects result type Tool to projected type ToolView using the
// "default" view.
func newToolView(res *Tool) *toolsviews.ToolView {
vres := &toolsviews.ToolView{
Name: &res.Name,
Version: &res.Version,
Packager: &res.Packager,
}
return vres
}
// newOperation converts projected type Operation to service type Operation.
func newOperation(vres *toolsviews.OperationView) *Operation {
res := &Operation{}
if vres.Status != nil {
res.Status = *vres.Status
}
return res
}
// newOperationView projects result type Operation to projected type
// OperationView using the "default" view.
func newOperationView(res *Operation) *toolsviews.OperationView {
vres := &toolsviews.OperationView{
Status: &res.Status,
}
return vres
}