-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
33 lines (26 loc) · 841 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
package main
import (
"net/http"
"github.com/spankie/go-influx/modules/shops"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
log "github.com/sirupsen/logrus"
)
func main() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
fileServer := http.StripPrefix("/assets/", http.FileServer(http.Dir("./public/assets")))
r.Get("/assets/*", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Cache-Control", "public, max-age=7776000")
fileServer.ServeHTTP(w, r)
})
r.Get("/", shops.GetAllProducts)
r.Get("/product/{ID}", shops.GetProduct)
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./public/404.html")
})
log.Print("👉 Server started at 127.0.0.1:3333")
http.ListenAndServe(":3333", r)
}