mtfosbot/module/apis/apis.go

32 lines
428 B
Go
Raw Permalink Normal View History

2018-09-10 10:13:27 +00:00
package apis
import (
"io"
"net/http"
)
2018-09-11 16:29:38 +00:00
// RequestObj -
2018-09-10 10:13:27 +00:00
type RequestObj struct {
Method string
2018-09-11 16:29:38 +00:00
URL string
2018-09-10 10:13:27 +00:00
Body io.Reader
Headers map[string]string
}
2018-09-11 16:29:38 +00:00
// GetRequest -
2018-09-10 10:13:27 +00:00
func GetRequest(r RequestObj) (req *http.Request, err error) {
2018-09-11 16:29:38 +00:00
req, err = http.NewRequest(r.Method, r.URL, r.Body)
2018-09-10 10:13:27 +00:00
if err != nil {
return
}
if len(r.Headers) > 0 {
for k, v := range r.Headers {
req.Header.Set(k, v)
}
}
return
}