Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
peer discovery
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
You can’t perform that action at this time.