...
1
4 package http
5
6 import (
7 "context"
8 "flag"
9 "fmt"
10 "net/http"
11 "time"
12 )
13
14 var (
15 debug = flag.Bool("ge_debug_http", false, "debug http code")
16 )
17
18 type HTTPIF interface {
19 Cookie(name string) *http.Cookie
20 Cookies() []*http.Cookie
21 Delete(url string, body []byte) *HTTPResponse
22 Get(url string) *HTTPResponse
23 GetStream(url string) *HTTPResponse
24 Head(url string) *HTTPResponse
25 Post(url string, body []byte) *HTTPResponse
26 Put(url string, body string) *HTTPResponse
27 SetHeader(key string, value string)
28 SetTimeout(dur time.Duration)
29 SetDebug(b bool)
30 SetCreds(username, password string)
31 }
32
33
34 func NewCachingClient(ctx context.Context) HTTPIF {
35 if *debug {
36 fmt.Printf("[go-easyops] New caching client..\n")
37 }
38 res := &cHTTP{}
39 res.ctx, res.ctx_cancel = context.WithCancel(ctx)
40
41 return res
42 }
43
44
45 func NewDirectClient() HTTPIF {
46 if *debug {
47 fmt.Printf("[go-easyops] New direct client..\n")
48 }
49 return &HTTP{}
50 }
51
View as plain text