-
Notifications
You must be signed in to change notification settings - Fork 14
/
defaultcallback.go
55 lines (42 loc) · 1.12 KB
/
defaultcallback.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
package common
import (
"context"
"net/http"
"time"
"github.com/anz-bank/sysl-go/validator"
"github.com/go-chi/chi"
)
func DefaultCallback() Callback {
return Callback{
UpstreamTimeout: 120 * time.Second,
DownstreamTimeout: 120 * time.Second,
RouterBasePath: "/",
UpstreamConfig: Config{},
}
}
type Callback struct {
UpstreamTimeout time.Duration
DownstreamTimeout time.Duration
RouterBasePath string
UpstreamConfig validator.Validator
}
type Config struct{}
func (c Config) Validate() error {
return nil
}
func (g Callback) AddMiddleware(ctx context.Context, r chi.Router) {
}
func (g Callback) BasePath() string {
return g.RouterBasePath
}
func (g Callback) Config() interface{} {
return g.UpstreamConfig
}
func (g Callback) HandleError(ctx context.Context, w http.ResponseWriter, kind Kind, message string, cause error) {
se := CreateError(ctx, kind, message, cause)
httpError := MapError(ctx, se)
httpError.WriteError(ctx, w)
}
func (g Callback) DownstreamTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc) {
return context.WithTimeout(ctx, g.DownstreamTimeout)
}