-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (27 loc) · 697 Bytes
/
Copy pathmain.go
File metadata and controls
38 lines (27 loc) · 697 Bytes
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/go-chi/chi"
"github.com/cmar82_nike/go-chi-api/db"
"github.com/cmar82_nike/go-chi-api/routes"
)
func main() {
if err := db.Init(); err != nil {
log.Fatal(err)
}
port := "8000"
if fromEnv := os.Getenv("PORT"); fromEnv != "" {
port = fromEnv
}
log.Printf("Starting up on http://localhost:%s", port)
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("Hello World!"))
})
r.Mount("/posts", routes.PostsResource{}.Routes())
r.Mount("/names", routes.NamesResource{}.Routes())
log.Fatal(http.ListenAndServe(":"+port, r))
}