package config import ( "os" "strconv" "git.velvettear.de/velvettear/loggo" ) var Output string var ApiKey string var Query string var Count int // initialize the config func Initialize() { ApiKey = os.Getenv("GOSPLASH_APIKEY") if len(ApiKey) == 0 { loggo.Fatal("no api key is specified", "make sure to export the environment variable 'GOSPLASH_APIKEY'") } Query = os.Getenv("GOSPLASH_QUERY") tmp, _ := strconv.Atoi(os.Getenv("GOSPLASH_COUNT")) if tmp <= 0 { tmp = 10 } Count = tmp if len(os.Args) > 1 { Output = os.Args[1] } if len(Output) == 0 { tmp, error := os.Getwd() if error != nil { loggo.Fatal("encountered an error getting the current working directory", error.Error()) } Output = tmp } stats, error := os.Stat(Output) if error != nil { if !os.IsNotExist(error) { loggo.Fatal("encountered an error getting the stats for output '"+Output+"'", error.Error()) } error = os.MkdirAll(Output, 0775) if error != nil { loggo.Fatal("encountered an error creating the output directory '"+Output+"'", error.Error()) } } else { if !stats.IsDir() { loggo.Fatal("specified output directory '" + Output + "' is not a valid directory") } } }