/
responses.go
75 lines (56 loc) · 1.14 KB
/
responses.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
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package api
import (
"fmt"
"net/http"
"github.com/mainflux/license"
"github.com/mainflux/mainflux"
)
var (
_ mainflux.Response = (*removeRes)(nil)
_ mainflux.Response = (*licenseRes)(nil)
)
type removeRes struct{}
func (res removeRes) Code() int {
return http.StatusNoContent
}
func (res removeRes) Headers() map[string]string {
return map[string]string{}
}
func (res removeRes) Empty() bool {
return true
}
type successRes struct{}
func (res successRes) Code() int {
return http.StatusOK
}
func (res successRes) Headers() map[string]string {
return map[string]string{}
}
func (res successRes) Empty() bool {
return true
}
type licenseRes struct {
license.License
created bool
}
func (res licenseRes) Code() int {
if res.created {
return http.StatusCreated
}
return http.StatusOK
}
func (res licenseRes) Headers() map[string]string {
ret := make(map[string]string)
if res.created {
ret["Location"] = fmt.Sprintf("/licenses/%s", res.ID)
}
return ret
}
func (res licenseRes) Empty() bool {
return res.created
}
type errorRes struct {
Err string `json:"error"`
}