func storageConnect(t *testing.T, name string) { tlog := &tLogger{t: t, name: name} if !testing.Short() { log.SetOutput(tlog) } alternateShutdown = tlog.shutdown os.Setenv("DBPREP_PATH", filepath.Join("..", "..", "dbprep")) if _, _, err := storage.Connect(); err != nil { shutdown(startupFailureShutdown) } }
func main() { // parse flags, if anything left over it's a usage problem flag.Parse() if flag.NArg() > 0 { flag.PrintDefaults() os.Exit(2) } if len(os.Getenv("DEBUG")) > 0 { *debugLog = true } if *debugLog { log.Printf("Debug log messages turned on.") } // client initialization if err := client.VerifyResources(); err != nil { log.Printf("Error during client initialization: %v", err) shutdown(startupFailureShutdown) } // storage initialization if cacheId, databaseId, err := storage.Connect(); err != nil { log.Printf("Error during storage initialization: %v", err) shutdown(startupFailureShutdown) } else { log.Printf("Connected to cache at %q", cacheId) log.Printf("Connected to database at %q", databaseId) } // port sensing port := os.Getenv("PORT") if port == "" { // running locally in dev mode port = "localhost:8080" } else { // running as a true server port = ":" + port } // catch signals shutdownOnSignal() // serve log.Printf("Listening on %s...", port) http.HandleFunc("/", serveHttp) err := http.ListenAndServe(port, nil) if err != nil { log.Printf("Listener failure: %v", err) shutdown(listenerFailureShutdown) } }
func testSetup(t *testing.T) { // log initialization tlog := &tLogger{t: t} if !testing.Short() { log.SetOutput(tlog) } else { log.SetOutput(os.Stderr) } // storage initialization os.Setenv("DBPREP_PATH", filepath.Join("..", "..", "dbprep")) cacheId, databaseId, err := storage.Connect() if err != nil { t.Fatalf("Error during storage initialization: %v", err) } log.Printf("Connected to cache at %q", cacheId) log.Printf("Connected to database at %q", databaseId) }
func main() { // log initialization log.SetOutput(os.Stderr) // storage initialization cacheId, databaseId, err := storage.Connect() if err != nil { log.Printf("Error during storage initialization: %v", err) os.Exit(1) } defer storage.Close() log.Printf("Connected to cache at %q", cacheId) log.Printf("Connected to database at %q", databaseId) // serve err = listener(os.Stdout, os.Stdin) if err != nil { log.Printf("CLI failure: %v", err) os.Exit(1) } os.Exit(0) }