-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (29 loc) · 928 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"log"
"net/http"
"os"
"github.com/BSski/RandomIntsStDevAPI/randomintsstdev"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func main() {
// Get "github.com/joho/godotenv" and uncomment this code if you want to run the app without Docker.
// err := godotenv.Load()
// if err != nil {
// log.Fatal("Error loading .env file", err)
// }
port := "8080"
if portFromEnv := os.Getenv("PORT"); portFromEnv != "" {
port = portFromEnv
}
log.Printf("Starting up on http://localhost:%s", port)
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("Hello World! You're probably looking for '/random/mean?requests=2&length=2' endpoint."))
})
r.Mount("/random", randomintsstdev.RandomAPIResource{}.Routes())
log.Fatal(http.ListenAndServe(":"+port, r))
}