Created
April 30, 2020 08:07
-
-
Save MonsterRob/6b5a4eb0d1f408d8a49d458425024839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"time" | |
"github.com/levigross/grequests" | |
) | |
type Method string | |
var ( | |
POST Method = "POST" | |
GET Method = "GET" | |
PUT Method = "PUT" | |
DELETE Method = "DELETE" | |
PATCH Method = "PATCH" | |
) | |
func TimeIt(method Method, url string, ro *grequests.RequestOptions) (milliseconds int64, resp *grequests.Response, err error) { | |
start := time.Now() | |
switch method { | |
case POST: | |
resp, err = grequests.Post(url, ro) | |
case GET: | |
resp, err = grequests.Get(url, ro) | |
case PUT: | |
resp, err = grequests.Put(url, ro) | |
case DELETE: | |
resp, err = grequests.Delete(url, ro) | |
case PATCH: | |
resp, err = grequests.Patch(url, ro) | |
default: | |
return 0, nil, errors.New("method not supported") | |
} | |
du := time.Since(start) | |
return du.Milliseconds(), resp, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment