Commit aa0a6e1a authored by zauberstuhl's avatar zauberstuhl

Add PushXmlToPrivate helper

related to #12
parent 2f26a6a7
......@@ -27,16 +27,23 @@ import (
"strings"
)
const (
PROTO_HTTP = "http://"
PROTO_HTTPS = "https://"
)
var timeout = time.Duration(10 * time.Second)
func PushXmlToPublic(host string, body io.Reader, ssl bool) error {
proto := "https://"
if !ssl {
proto = "http://"
}
func PushXmlToPrivate(host, guid string, body io.Reader) error {
return pushXml(host, "/receive/users/" + guid, PROTO_HTTPS, body)
}
func PushXmlToPublic(host string, body io.Reader) error {
return pushXml(host, "/receive/public", PROTO_HTTPS, body)
}
req, err := http.NewRequest("POST",
proto + host + "/receive/public", body)
func pushXml(host, endpoint, proto string, body io.Reader) error {
req, err := http.NewRequest("POST", proto + host + endpoint, body)
if err != nil {
return err
}
......@@ -47,16 +54,16 @@ func PushXmlToPublic(host string, body io.Reader, ssl bool) error {
}
resp, err := client.Do(req)
if err != nil {
if ssl {
info("Retry with", proto, "on", host, err)
return PushXmlToPublic(host, body, false)
if proto == PROTO_HTTPS {
info("Retry with", PROTO_HTTP, "on", host, err)
return pushXml(host, endpoint, PROTO_HTTP, body)
}
return err
}
defer resp.Body.Close()
if !(resp.StatusCode == 200 || resp.StatusCode == 202) {
return errors.New("PushXmlToPublic results in: " + resp.Status)
return errors.New("pushXml results in: " + resp.Status)
}
return nil
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment