refactor
Showing
1 changed file
with
17 additions
and
24 deletions
| ... | @@ -73,49 +73,42 @@ func SetDefaultSetting(setting BeegoHttpSettings) { | ... | @@ -73,49 +73,42 @@ func SetDefaultSetting(setting BeegoHttpSettings) { |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | // Get returns *BeegoHttpRequest with GET method. | 76 | // return *BeegoHttpRequest with specific method |
| 77 | func Get(url string) *BeegoHttpRequest { | 77 | func newBeegoRequest(url, method string) *BeegoHttpRequest { |
| 78 | var req http.Request | 78 | req := http.Request{ |
| 79 | Proto: "HTTP/1.1", | ||
| 80 | ProtoMajor: 1, | ||
| 81 | ProtoMinor: 1, | ||
| 82 | } | ||
| 79 | var resp http.Response | 83 | var resp http.Response |
| 80 | req.Method = "GET" | 84 | req.Method = method |
| 81 | req.Header = http.Header{} | 85 | req.Header = http.Header{} |
| 82 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} | 86 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} |
| 83 | } | 87 | } |
| 84 | 88 | ||
| 89 | // Get returns *BeegoHttpRequest with GET method. | ||
| 90 | func Get(url string) *BeegoHttpRequest { | ||
| 91 | return newBeegoRequest(url, "GET") | ||
| 92 | } | ||
| 93 | |||
| 85 | // Post returns *BeegoHttpRequest with POST method. | 94 | // Post returns *BeegoHttpRequest with POST method. |
| 86 | func Post(url string) *BeegoHttpRequest { | 95 | func Post(url string) *BeegoHttpRequest { |
| 87 | var req http.Request | 96 | return newBeegoRequest(url, "POST") |
| 88 | var resp http.Response | ||
| 89 | req.Method = "POST" | ||
| 90 | req.Header = http.Header{} | ||
| 91 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} | ||
| 92 | } | 97 | } |
| 93 | 98 | ||
| 94 | // Put returns *BeegoHttpRequest with PUT method. | 99 | // Put returns *BeegoHttpRequest with PUT method. |
| 95 | func Put(url string) *BeegoHttpRequest { | 100 | func Put(url string) *BeegoHttpRequest { |
| 96 | var req http.Request | 101 | return newBeegoRequest(url, "PUT") |
| 97 | var resp http.Response | ||
| 98 | req.Method = "PUT" | ||
| 99 | req.Header = http.Header{} | ||
| 100 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} | ||
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | // Delete returns *BeegoHttpRequest DELETE GET method. | 104 | // Delete returns *BeegoHttpRequest DELETE GET method. |
| 104 | func Delete(url string) *BeegoHttpRequest { | 105 | func Delete(url string) *BeegoHttpRequest { |
| 105 | var req http.Request | 106 | return newBeegoRequest(url, "DELETE") |
| 106 | var resp http.Response | ||
| 107 | req.Method = "DELETE" | ||
| 108 | req.Header = http.Header{} | ||
| 109 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} | ||
| 110 | } | 107 | } |
| 111 | 108 | ||
| 112 | // Head returns *BeegoHttpRequest with HEAD method. | 109 | // Head returns *BeegoHttpRequest with HEAD method. |
| 113 | func Head(url string) *BeegoHttpRequest { | 110 | func Head(url string) *BeegoHttpRequest { |
| 114 | var req http.Request | 111 | return newBeegoRequest(url, "HEAD") |
| 115 | var resp http.Response | ||
| 116 | req.Method = "HEAD" | ||
| 117 | req.Header = http.Header{} | ||
| 118 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} | ||
| 119 | } | 112 | } |
| 120 | 113 | ||
| 121 | // BeegoHttpSettings | 114 | // BeegoHttpSettings | ... | ... |
-
Please register or sign in to post a comment