|
|
@ -31,40 +31,39 @@ var ( |
|
|
|
session sessionInfo |
|
|
|
session sessionInfo |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func downloadFile(filepath string, url string) error { |
|
|
|
const ( |
|
|
|
|
|
|
|
DistributionFileName = "distribution_config.txt" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func downloadFile(filepath string, url string) { |
|
|
|
// Create the file
|
|
|
|
// Create the file
|
|
|
|
out, err := os.Create(filepath) |
|
|
|
out, err := os.Create(filepath) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer out.Close() |
|
|
|
defer out.Close() |
|
|
|
|
|
|
|
|
|
|
|
log.Println(url) |
|
|
|
|
|
|
|
// Get the data
|
|
|
|
// Get the data
|
|
|
|
resp, err := http.Get(url) |
|
|
|
resp, err := http.Get(url) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
|
|
|
|
log.Println(resp.Body) |
|
|
|
|
|
|
|
// Write the body to file
|
|
|
|
// Write the body to file
|
|
|
|
_, err = io.Copy(out, resp.Body) |
|
|
|
_, err = io.Copy(out, resp.Body) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func readConfigFile() [][]string { |
|
|
|
func readConfigFile() [][]string { |
|
|
|
configFile := "distribution_config.txt" |
|
|
|
downloadFile(DistributionFileName, setting.configURL) |
|
|
|
err := downloadFile(configFile, setting.configURL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
file, err := os.Open(DistributionFileName) |
|
|
|
file, err := os.Open(configFile) |
|
|
|
|
|
|
|
defer file.Close() |
|
|
|
defer file.Close() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("Failed to read config file ", configFile, |
|
|
|
log.Fatal("Failed to read config file ", DistributionFileName, |
|
|
|
"\nNOTE: The config path should be relative to commander.") |
|
|
|
"\nNOTE: The config path should be relative to commander.") |
|
|
|
} |
|
|
|
} |
|
|
|
fscanner := bufio.NewScanner(file) |
|
|
|
fscanner := bufio.NewScanner(file) |
|
|
@ -76,10 +75,6 @@ func readConfigFile() [][]string { |
|
|
|
} |
|
|
|
} |
|
|
|
log.Println(result) |
|
|
|
log.Println(result) |
|
|
|
return result |
|
|
|
return result |
|
|
|
} else { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleCommand(command string) { |
|
|
|
func handleCommand(command string) { |
|
|
@ -231,7 +226,7 @@ func serve() { |
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
ip := flag.String("ip", "127.0.0.1", "The ip of commander, i.e. this machine") |
|
|
|
ip := flag.String("ip", "127.0.0.1", "The ip of commander, i.e. this machine") |
|
|
|
port := flag.String("port", "8080", "The port which the commander uses to communicate with soldiers") |
|
|
|
port := flag.String("port", "8080", "The port which the commander uses to communicate with soldiers") |
|
|
|
configURL := flag.String("config_url", "http://unique-bucket-bin.amazonaws.com/distribution_config.txt", "The config URL") |
|
|
|
configURL := flag.String("config_url", "https://s3-us-west-2.amazonaws.com/unique-bucket-bin/distribution_config.txt", "The config URL") |
|
|
|
flag.Parse() |
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
|
|
config(*ip, *port, *configURL) |
|
|
|
config(*ip, *port, *configURL) |
|
|
|