forked from kiali/kiali
/
util.go
45 lines (37 loc) · 1006 Bytes
/
util.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
package graph
import (
nethttp "net/http"
)
type Response struct {
Message string
Code int
}
// Error panics with InternalServerError and the provided message
func Error(message string) {
Panic(message, nethttp.StatusInternalServerError)
}
// BadRequest panics with BadRequest and the provided message
func BadRequest(message string) {
Panic(message, nethttp.StatusBadRequest)
}
// Forbidden panics with Forbidden and the provided message
func Forbidden(message string) {
Panic(message, nethttp.StatusForbidden)
}
// Panic panics with the provided HTTP response code and message
func Panic(message string, code int) Response {
panic(Response{
Message: message,
Code: code,
})
}
// CheckError panics with the supplied error if it is non-nil
func CheckError(err error) {
if err != nil {
panic(err.Error)
}
}
// IsOK just validates that a telemetry label value is not empty or unknown
func IsOK(telemetryVal string) bool {
return telemetryVal != "" && telemetryVal != Unknown
}