blob: 006fc31e1df7e347082ce4f4a4f94b6fc6290baf [file] [log] [blame]
giolekvaa4a153b2020-05-12 11:49:53 +04001package appmanager
2
3import (
4 "fmt"
giolekva4a03ba32020-05-13 21:59:26 +04005 "io/ioutil"
giolekvaa4a153b2020-05-12 11:49:53 +04006 "net/http"
7 "strings"
8)
9
10func InstallSchema(schema *Schema, apiAddr string) error {
11 if schema == nil || len(schema.Schema) == 0 {
12 return nil
13 }
14 resp, err := http.Post(apiAddr, "application/text", strings.NewReader(schema.Schema))
15 if err != nil {
16 return err
17 }
18 if resp.StatusCode != http.StatusOK {
giolekva4a03ba32020-05-13 21:59:26 +040019 body, _ := ioutil.ReadAll(resp.Body)
20 return fmt.Errorf("Failed request with status code: %d %s", resp.StatusCode, string(body))
giolekvaa4a153b2020-05-12 11:49:53 +040021 }
22 return nil
23}