-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathoptions.go
More file actions
76 lines (66 loc) · 1.46 KB
/
Copy pathoptions.go
File metadata and controls
76 lines (66 loc) · 1.46 KB
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
76
package timeout
import (
"github.com/gin-gonic/gin"
"net/http"
"time"
)
type CallBackFunc func(*http.Request)
type GinCtxCallBackFunc func(*gin.Context)
type Option func(*TimeoutWriter)
type TimeoutOptions struct {
CallBack CallBackFunc
GinCtxCallBack GinCtxCallBackFunc
Timeout time.Duration
Response Response
}
func WithTimeout(d time.Duration) Option {
return func(t *TimeoutWriter) {
t.Timeout = d
}
}
// WithErrorHttpCode Optional parameters
func WithErrorHttpCode(code int) Option {
return func(t *TimeoutWriter) {
if t.Response == nil {
t.Response = defaultResponse
}
t.Response.SetCode(code)
}
}
// WithDefaultMsg Optional parameters
func WithDefaultMsg(resp interface{}) Option {
return func(t *TimeoutWriter) {
if t.Response == nil {
t.Response = defaultResponse
}
t.Response.SetContent(resp)
}
}
// WithContentType Optional parameters
func WithContentType(ct string) Option {
return func(t *TimeoutWriter) {
if t.Response == nil {
t.Response = defaultResponse
}
t.Response.SetContentType(ct)
}
}
func WithResponse(resp Response) Option {
return func(t *TimeoutWriter) {
if resp != nil {
t.Response = resp
}
}
}
// WithCallBack Optional parameters
func WithCallBack(f CallBackFunc) Option {
return func(t *TimeoutWriter) {
t.CallBack = f
}
}
// WithGinCtxCallBack Optional parameters
func WithGinCtxCallBack(f GinCtxCallBackFunc) Option {
return func(t *TimeoutWriter) {
t.GinCtxCallBack = f
}
}