-
Notifications
You must be signed in to change notification settings - Fork 29
/
options.go
54 lines (45 loc) · 986 Bytes
/
options.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
package timeout
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
type CallBackFunc func(*http.Request)
type GinCtxCallBackFunc func(*gin.Context)
type Option func(*TimeoutWriter)
type TimeoutOptions struct {
CallBack CallBackFunc
GinCtxCallBack GinCtxCallBackFunc
DefaultMsg interface{}
Timeout time.Duration
ErrorHttpCode int
}
func WithTimeout(d time.Duration) Option {
return func(t *TimeoutWriter) {
t.Timeout = d
}
}
// Optional parameters
func WithErrorHttpCode(code int) Option {
return func(t *TimeoutWriter) {
t.ErrorHttpCode = code
}
}
// Optional parameters
func WithDefaultMsg(resp interface{}) Option {
return func(t *TimeoutWriter) {
t.DefaultMsg = resp
}
}
// Optional parameters
func WithCallBack(f CallBackFunc) Option {
return func(t *TimeoutWriter) {
t.CallBack = f
}
}
// Optional parameters
func WithGinCtxCallBack(f GinCtxCallBackFunc) Option {
return func(t *TimeoutWriter) {
t.GinCtxCallBack = f
}
}