-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathresponse.go
More file actions
154 lines (127 loc) · 3.74 KB
/
response.go
File metadata and controls
154 lines (127 loc) · 3.74 KB
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
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
package api
import (
"github.com/linuxboot/contest/pkg/job"
"github.com/linuxboot/contest/pkg/types"
"github.com/insomniacslk/xjson"
)
// ResponseType defines the storage type of a response type.
type ResponseType int32
// The various response types used in the Response struct.
const (
ResponseTypeStart ResponseType = iota
ResponseTypeStop
ResponseTypeStatus
ResponseTypeRetry
ResponseTypeVersion
ResponseTypeList
)
// ResponseTypeToName maps response types to their names.
var ResponseTypeToName = map[ResponseType]string{
ResponseTypeStart: "ResponseTypeStart",
ResponseTypeStop: "ResponseTypeStop",
ResponseTypeStatus: "ResponseTypeStatus",
ResponseTypeRetry: "ResponseTypeRetry",
ResponseTypeVersion: "ResponseTypeVersion",
ResponseTypeList: "ResponseTypeList",
}
// Response is the type returned to any API request.
type Response struct {
ServerID string
Type ResponseType
Data ResponseData
Err error
}
// ResponseData is the interface type implemented by the various response types.
type ResponseData interface {
Type() ResponseType
}
// ResponseDataStart is the response type for a Start request.
type ResponseDataStart struct {
JobID types.JobID
}
// Type returns the response type.
func (r ResponseDataStart) Type() ResponseType {
return ResponseTypeStart
}
// ResponseDataStop is the response type for a Stop request.
type ResponseDataStop struct {
}
// Type returns the response type.
func (r ResponseDataStop) Type() ResponseType {
return ResponseTypeStop
}
// ResponseDataStatus is the response type for a Status request.
type ResponseDataStatus struct {
Status *job.Status
}
// Type returns the response type.
func (r ResponseDataStatus) Type() ResponseType {
return ResponseTypeStatus
}
// ResponseDataRetry is the response type for a Retry request.
type ResponseDataRetry struct {
JobID types.JobID
NewJobID types.JobID
}
// Type returns the response type.
func (r ResponseDataRetry) Type() ResponseType {
return ResponseTypeRetry
}
// ResponseDataList is the response type for a List request.
type ResponseDataList struct {
JobIDs []types.JobID
}
// Type returns the response type.
func (r ResponseDataList) Type() ResponseType {
return ResponseTypeList
}
// ResponseDataVersion is the response type for a Version request.
type ResponseDataVersion struct {
Version uint32
}
// Type returns the response type.
func (r ResponseDataVersion) Type() ResponseType {
return ResponseTypeVersion
}
// Typesafe versions of Response, to replace the untyped Response in the future
// already used by client Transport interface
// StatusResponse is a typesafe version of Response with a Status payload
type StatusResponse struct {
ServerID string
Data ResponseDataStatus
Err *xjson.Error
}
// StartResponse is a typesafe version of Response with a Status payload
type StartResponse struct {
ServerID string
Data ResponseDataStart
Err *xjson.Error
}
// StopResponse is a typesafe version of Response with a Status payload
type StopResponse struct {
ServerID string
Data ResponseDataStop
Err *xjson.Error
}
// RetryResponse is a typesafe version of Response with a Status payload
type RetryResponse struct {
ServerID string
Data ResponseDataRetry
Err *xjson.Error
}
// ListResponse is a typesafe version of Response with a List payload
type ListResponse struct {
ServerID string
Data ResponseDataList
Err *xjson.Error
}
// VersionResponse is a typesafe version of Response with a Status payload
type VersionResponse struct {
ServerID string
Data ResponseDataVersion
Err *xjson.Error
}