commander downloads config file on config

pull/40/head
alok 6 years ago
parent 8df48c85c8
commit fc18e354ec
  1. 27
      aws-experiment-launch/experiment/commander/main.go

@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@ -58,6 +59,32 @@ func handleCommand(command string) {
switch cmd := args[0]; cmd {
case "config":
{
out, err := os.Create(setting.configFile)
if err != nil {
log.Fatal("Failed to create local file", err)
}
defer out.Close()
// get remote config file
resp, err := http.Get(setting.configURL)
if err != nil {
log.Fatal("Failed to read file content")
}
defer resp.Body.Close()
// copy remote to local
_, err = io.Copy(out, resp.Body)
if err != nil {
log.Fatal("Failed to copy file")
}
// log config file
content, err := ioutil.ReadFile(setting.configFile)
if err != nil {
log.Fatal(err)
}
log.Println("Successfully downloaded config")
log.Println(string(content))
setting.configs = readConfigFile()
log.Println("Loaded config file", setting.configs)
}

Loading…
Cancel
Save