forked from s32x/httpclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.go
89 lines (75 loc) · 2.52 KB
/
crud.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package httpclient
import (
"fmt"
"net/http"
"sync"
)
// Postf takes a format and a variadic of arguments and returns a prepopulated
// Post request
func (c *Client) Postf(format string, a ...interface{}) *Request {
return c.Post(fmt.Sprintf(format, a...))
}
// Post takes a path and returns a prepopulated Post request
func (c *Client) Post(path string) *Request {
return c.Request(http.MethodPost, path)
}
// Putf takes a format and a variadic of arguments and returns a prepopulated
// Put request
func (c *Client) Putf(format string, a ...interface{}) *Request {
return c.Put(fmt.Sprintf(format, a...))
}
// Put takes a path and returns a prepopulated Put request
func (c *Client) Put(path string) *Request {
return c.Request(http.MethodPut, path)
}
// Patchf takes a format and a variadic of arguments and returns a prepopulated
// Patch request
func (c *Client) Patchf(format string, a ...interface{}) *Request {
return c.Patch(fmt.Sprintf(format, a...))
}
// Patch takes a path and returns a prepopulated Patch request
func (c *Client) Patch(path string) *Request {
return c.Request(http.MethodPatch, path)
}
// Headf takes a format and a variadic of arguments and returns a prepopulated
// Head request
func (c *Client) Headf(format string, a ...interface{}) *Request {
return c.Head(fmt.Sprintf(format, a...))
}
// Head takes a path and returns a prepopulated Head request
func (c *Client) Head(path string) *Request {
return c.Request(http.MethodHead, path)
}
// Getf takes a format and a variadic of arguments and returns a prepopulated
// Get request
func (c *Client) Getf(format string, a ...interface{}) *Request {
return c.Get(fmt.Sprintf(format, a...))
}
// Get takes a path and returns a prepopulated Get request
func (c *Client) Get(path string) *Request {
return c.Request(http.MethodGet, path)
}
// Deletef takes a format and a variadic of arguments and returns a prepopulated
// Delete request
func (c *Client) Deletef(format string, a ...interface{}) *Request {
return c.Delete(fmt.Sprintf(format, a...))
}
// Delete takes a path and returns a prepopulated Delete request
func (c *Client) Delete(path string) *Request {
return c.Request(http.MethodDelete, path)
}
// Request creates a new Request copying configuration from the base Client
func (c *Client) Request(method, path string) *Request {
r := &Request{
client: c.client,
method: method,
baseURL: c.baseURL,
path: path,
header: sync.Map{},
}
c.header.Range(func(key, val interface{}) bool {
r.header.Store(key, val)
return true
})
return r
}