Implementation of route add

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-03 20:56:40 +02:00
parent 9f7fc8ce62
commit 4357b1ad20
2 changed files with 37 additions and 29 deletions
+10 -23
View File
@@ -1,31 +1,18 @@
package client
import (
"errors"
"net/http"
"strings"
"bytes"
"encoding/json"
"github.com/BBVA/kapow/internal/http"
)
// AddRoute will add a new route in kapow
func AddRoute(host, path, method, entrypoint, command string) error {
reqData, err := http.NewRequest(
"PUT",
host+"/routes",
strings.NewReader(command),
)
if err != nil {
return err
}
var client = new(http.Client)
res, err := client.Do(reqData)
if err != nil {
return err
}
if res.StatusCode < 200 || res.StatusCode >= 300 {
return errors.New(res.Status)
}
return nil
url := host + "/routes"
body, _ := json.Marshal(map[string]string{
"method": method,
"url_pattern": path,
"entrypoint": entrypoint,
"command": command})
return http.Put(url, "application/json", bytes.NewReader(body), nil)
}