Rework directory structure

Co-authored-by: Héctor Hurtado <hector.hurtado@bbva.com>
This commit is contained in:
pancho horrillo
2019-10-03 12:05:53 +02:00
parent 8b7d1d69e7
commit 23128026c7
12 changed files with 12 additions and 12 deletions
+36
View File
@@ -0,0 +1,36 @@
package client
import (
"fmt"
"io"
"net/http"
)
const (
errMandatoryParam = "Mandatory parameter %s missing"
errInvalidURL = "kapowURL, handlerId or path has invalid format"
errNotFound = "Resource Item Not Found"
errNotValidResource = "Invalid Resource Path"
serverURLTemplate = "%s/%s%s"
)
func SetData(kapowURL, handlerId, path string, r io.Reader) error {
req, err := http.NewRequest("PUT", fmt.Sprintf(serverURLTemplate, kapowURL, handlerId, path), r)
if err != nil {
return err
}
kpowClient := &http.Client{}
if resp, err := kpowClient.Do(req); err != nil {
return err
} else if resp.StatusCode == http.StatusNoContent {
return fmt.Errorf(errNotFound)
} else if resp.StatusCode == http.StatusBadRequest {
return fmt.Errorf(errNotValidResource)
} else if resp.StatusCode >= http.StatusNotFound {
return fmt.Errorf(resp.Status[4:])
}
return nil
}