blob: 762868690fb26c6ef91cfa8bbc67ac94a064fe1d [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
giolekvab1f19ee2020-05-16 11:31:20 +040010func InstallSchema(schema Schema, apiAddr string) error {
11 if len(schema.Schema) == 0 {
giolekvaa4a153b2020-05-12 11:49:53 +040012 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}