2019-10-03 20:22:22 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2019-11-24 21:20:07 +00:00
|
|
|
"encoding/json"
|
2019-10-03 20:22:22 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2019-11-24 21:20:07 +00:00
|
|
|
type Status struct {
|
|
|
|
Success bool `json:"success"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
|
|
|
|
2019-10-03 20:22:22 +00:00
|
|
|
func ResponseGet(endpoint string) ([]byte, error) {
|
|
|
|
resp, err := http.Get(endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return body, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResponsePost(endpoint string, form url.Values) ([]byte, error) {
|
|
|
|
resp, err := http.PostForm(endpoint, form)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return body, err
|
|
|
|
}
|
|
|
|
|
2019-11-24 21:20:07 +00:00
|
|
|
func ResponseStatus(endpoint string, form url.Values) (*Status, error) {
|
|
|
|
resp, err := ResponsePost(endpoint, form)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
status := &Status{}
|
|
|
|
err = json.Unmarshal(resp, &status)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, nil
|
2019-10-03 20:22:22 +00:00
|
|
|
}
|