-
Notifications
You must be signed in to change notification settings - Fork 3
/
endpoints.go
105 lines (84 loc) · 2 KB
/
endpoints.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
/*
Copyright 2021 Adevinta
*/
package endpoint
import (
"encoding/json"
"net/http"
"github.com/go-kit/kit/endpoint"
)
// ScanEngineService contains the services needed by all the endpoints.
type ScanEngineService interface {
HealthChecker
ScanCreator
ScanGetter
}
// Endpoints contains all available endpoints for this api
type Endpoints struct {
Healthcheck endpoint.Endpoint
CreateScan endpoint.Endpoint
ListScans endpoint.Endpoint
GetScan endpoint.Endpoint
GetScanChecks endpoint.Endpoint
GetScanStats endpoint.Endpoint
GetCheck endpoint.Endpoint
AbortScan endpoint.Endpoint
}
// MakeEndpoints initialize endpoints using the given service
func MakeEndpoints(s ScanEngineService) *Endpoints {
return &Endpoints{
Healthcheck: makeHealthcheckEndpoint(s),
CreateScan: makeCreateScanEndpoint(s),
ListScans: makeListScansEndpoint(s),
GetScan: makeGetScanEndpoint(s),
GetScanChecks: makeGetScanChecksEndpoint(s),
GetScanStats: makeGetScanStatsEndpoint(s),
GetCheck: makeGetCheckEndpoint(s),
AbortScan: makeAbortScanEndpoint(s),
}
}
type HTTPResponse interface {
StatusCode() int
}
type Created struct {
Data interface{}
}
func (c Created) StatusCode() int {
return http.StatusCreated
}
func (c Created) MarshalJSON() ([]byte, error) {
return json.Marshal(c.Data)
}
type Ok struct {
Data interface{}
}
func (c Ok) StatusCode() int {
return http.StatusOK
}
func (c Ok) MarshalJSON() ([]byte, error) {
return json.Marshal(c.Data)
}
type Accepted struct {
Data interface{}
}
func (c Accepted) StatusCode() int {
return http.StatusAccepted
}
type ServerDown struct {
Data interface{}
}
func (c ServerDown) StatusCode() int {
return http.StatusInternalServerError
}
func (c ServerDown) MarshalJSON() ([]byte, error) {
return json.Marshal(c.Data)
}
type NoContent struct {
Data interface{}
}
func (c NoContent) StatusCode() int {
return http.StatusNoContent
}
func (c NoContent) MarshalJSON() ([]byte, error) {
return json.Marshal(c.Data)
}