Created
August 28, 2018 08:05
-
-
Save kesor/29a13789d513205b584ad2ae82a029c8 to your computer and use it in GitHub Desktop.
peer discovery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
"time" | |
) | |
func printFatal(e error) { | |
fmt.Printf("ERROR: %s\n", e) | |
os.Exit(1) | |
} | |
var retryAttempts = 5 | |
var retryTimeout time.Duration = 10 | |
func main() { | |
var s, sep string | |
var globalConfig map[string]string | |
var peersAddress []string | |
globalConfig = make(map[string]string) | |
globalConfig["PEERS"] = os.Getenv("WRAP_PEERS") | |
if val, ok := globalConfig["PEERS"]; ok { | |
peers := strings.Split(val, ",") | |
fmt.Printf("peers: %v\n", peers) | |
for retryAttempts > 0 && len(peersAddress) < len(peers) { | |
retryAttempts = retryAttempts - 1 | |
for _, peer := range peers { | |
fmt.Printf("peer: %v\n", peer) | |
} | |
time.Sleep(retryTimeout * time.Second) | |
} | |
} else { | |
printFatal(fmt.Errorf("WRAP_PEERS environment variable is missing")) | |
} | |
for i := 1; i < len(os.Args); i++ { | |
s += sep + os.Args[i] | |
sep = " " | |
} | |
fmt.Println(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment