package main import ( "fmt" "net/http" "os" "strings" ) var slash = string(os.PathSeparator) var baseURL string var storage = "storage" var actors = make(map[string]*Actor) const libName = "jsonpub" const version = "0.0.1" var client = http.Client{} // Setup sets our environment up func Setup() { // Load base url baseURL = os.Getenv("BASE_URL") if len(baseURL) < 1 { fmt.Printf("BASE_URL not configured") os.Exit(1) } // check if it ends with a / and append one if not if baseURL[len(baseURL)-1:] != "/" { baseURL += "/" } // print baseURL fmt.Println("Base URL:", baseURL) cwd, _ := os.Getwd() fmt.Println("Storage Location:", cwd+slash+storage) } // Get actors from env vars // NAMES: names of actors // {{NAME}}_IRI: IRI of actor // {{NAME}}_PK: Storage location of private Key of actor func SetupActors() { namesString := os.Getenv("NAMES") if len(namesString) < 1 { fmt.Printf("NAMES not configured") os.Exit(1) } names := strings.Split(namesString, ",") for _, name := range names { iri := os.Getenv(strings.ToUpper(name) + "_IRI") if len(iri) < 1 { fmt.Printf(strings.ToUpper(name) + "_IRI not configured") os.Exit(1) } feed := os.Getenv(strings.ToUpper(name) + "_FEED") if len(feed) < 1 { fmt.Printf(strings.ToUpper(name) + "_FEED not configured") os.Exit(1) } pk := os.Getenv(strings.ToUpper(name) + "_PK") if len(pk) < 1 { fmt.Printf(strings.ToUpper(name) + "_PK not configured") os.Exit(1) } actor, err := GetActor(name, iri, feed, pk) actors[name] = &actor if err != nil { fmt.Printf(err.Error()) os.Exit(1) } } }