23 lines
474 B
Go
23 lines
474 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/http"
|
|
)
|
|
|
|
func Post(url string, body interface{}) (*http.Response, error) {
|
|
log.Debugf("POST %s", url)
|
|
log.Debugf("Body: %v", body)
|
|
jsonBody, err := json.Marshal(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonBody))
|
|
log.Debugf("Status: %d", resp.StatusCode)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|