-
Notifications
You must be signed in to change notification settings - Fork 307
/
http.go
45 lines (33 loc) · 1.12 KB
/
http.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
/*
Http Interface Use this instead of http package.
usage example
import "github.com/rudderlabs/rudder-server/utils/sysUtils"
var Http sysUtils.HttpI = &sysUtils.Http{}
or
var Http sysUtils.HttpI = sysUtils.NewHttp()
...
Http.NewRequest(...)
*/
//go:generate mockgen -destination=../../mocks/utils/sysUtils/mock_http.go -package mock_sysUtils github.com/rudderlabs/rudder-server/utils/sysUtils HttpI
package sysUtils
import (
"context"
"io"
"net/http"
)
type HttpI interface {
NewRequest(method, url string, body io.Reader) (*http.Request, error)
NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
}
type Http struct{}
// NewHttp returns a Http instance
func NewHttp() *Http {
return &Http{}
}
// NewRequest wraps NewRequestWithContext using the background context.
func (*Http) NewRequest(method, url string, body io.Reader) (*http.Request, error) {
return http.NewRequest(method, url, body)
}
func (*Http) NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) {
return http.NewRequestWithContext(ctx, method, url, body)
}