-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
51 lines (46 loc) · 1.19 KB
/
context.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
package haki
import (
"errors"
"github.com/rjansen/l"
)
const (
ContentTypeHeader = "Content-Type"
ContentLengthHeader = "Content-Length"
AcceptHeader = "Accept"
RequestContextHeader = "X-Request-Context"
RequestIDHeader = "X-Request-Id"
AuthorizationHeader = "Authorization"
)
var (
ErrInvalidContentType = errors.New("Invalid ContentType. Only: aplication/json, application/octet-stream are valid")
ErrInvalidAccept = errors.New("Invalid Accept. Only: aplication/json, application/octet-stream are valid")
)
//SetupAll calls all provided setup functions and return all raised errors
func SetupAll(setupFuncs ...SetupFunc) []error {
var errs []error
for i, v := range setupFuncs {
if err := v(); err != nil {
l.Warn("contex.SetupSilent",
l.Int("index", i),
l.Struct("func", v),
l.Err(err),
)
errs = append(errs, err)
}
}
return errs
}
//Setup calls the provided setup functions and return at the first raised error
func Setup(setupFuncs ...SetupFunc) error {
for i, v := range setupFuncs {
if err := v(); err != nil {
l.Error("contex.Setup",
l.Int("index", i),
l.Struct("func", v),
l.Err(err),
)
return err
}
}
return nil
}