eab777751c5817f600cd12d09671fea2b4e71725 — HokieGeek a month ago c6db8a9 v1.4.1
Adding support to run as Cloud Run
1 files changed, 8 insertions(+), 3 deletions(-)

M cmd/biologistd/main.go
M cmd/biologistd/main.go => cmd/biologistd/main.go +8 -3
@@ 304,9 304,14 @@   func main() {
  	logger := log.New(os.Stdout, "[biologistd] ", 0)
- 	portPtr := flag.Int("port", 80, "Specify the port to use")
+ 	portPtr := flag.String("port", "8080", "Specify the port to use")
  	flag.Parse()
  
+ 	port := os.Getenv("PORT")
+ 	if port == "" {
+ 		port = *portPtr
+ 	}
+ 
  	mgr := biologist.NewManager()
  
  	mux := mux.NewRouter()


@@ 329,8 334,8 @@ exposedOk := handlers.ExposedHeaders([]string{"Content-Type", "Content-Length", "Accept-Encoding", "Authorization", "Etag"})
  	methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"})
  
- 	log.Printf("Started server on port %d\n", *portPtr)
- 	http.ListenAndServe(fmt.Sprintf(":%d", *portPtr), handlers.CORS(originsOk, headersOk, methodsOk, exposedOk)(mux))
+ 	log.Printf("Started server on port %s\n", port)
+ 	http.ListenAndServe(fmt.Sprintf(":%s", port), handlers.CORS(originsOk, headersOk, methodsOk, exposedOk)(mux))
  }
  
  // vim: set foldmethod=marker: