func main()

in code/client/main.go [38:75]


func main() {
	dbHost := os.Getenv("DBHOST")
	port := os.Getenv("PORT")

	if port == "" {
		port = defaultPort
	}

	if dbHost == "" {
		log.Fatal("DBHOST env not set. Need ip/host with mongo on port", mongoport)
	}

	ctx := context.Background()
	svc, err := newTrainerService(ctx, dbHost, mongoport)
	if err != nil {
		log.Fatal("error connecting to mongo: ", err)
	}

	fSys, err := fs.Sub(static, "static")
	if err != nil {
		panic(err)
	}

	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/healthz", healthHandler).Methods(http.MethodGet)
	router.HandleFunc("/api/v1/healthz", healthHandler).Methods(http.MethodGet)
	router.HandleFunc("/api/v1/trainer", listHandler(svc)).Methods(http.MethodGet)
	router.HandleFunc("/api/v1/trainer", createHandler(svc)).Methods(http.MethodPost)
	router.HandleFunc("/api/v1/trainer", deleteHandler(svc)).Methods(http.MethodDelete)
	router.HandleFunc("/api/v1/trainer", updateHandler(svc)).Methods(http.MethodPut)
	router.PathPrefix("/").Handler(logWrap(http.FileServer(http.FS(fSys))))

	headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"})
	originsOk := handlers.AllowedOrigins([]string{"*"})
	methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS", "DELETE"})

	log.Fatal(http.ListenAndServe(":"+port, handlers.CORS(originsOk, headersOk, methodsOk)(router)))
}