-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (32 loc) · 1.13 KB
/
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
39
40
41
package main
import (
"fmt"
"lenslocked/controllers"
"lenslocked/templates"
"lenslocked/views"
"net/http"
"github.com/go-chi/chi/v5"
)
func main() {
r := chi.NewRouter()
//parse templete
//only use MUST in main func
r.Get("/", controllers.StaticHandler(views.Must(
views.ParseFS(templates.FS, "home.gohtml", "tailwind.gohtml"))))
r.Get("/contact", controllers.StaticHandler(views.Must(
views.ParseFS(templates.FS, "contact.gohtml", "tailwind.gohtml"))))
r.Get("/contact/{id}", controllers.StaticHandler(views.Must(
views.ParseFS(templates.FS, "contact.gohtml", "tailwind.gohtml"))))
r.Get("/faq", controllers.FAQ(views.Must(
views.ParseFS(templates.FS, "faq.gohtml", "tailwind.gohtml"))))
var usersC controllers.Users
usersC.Templates.New = views.Must(
views.ParseFS(templates.FS, "signup.gohtml", "tailwind.gohtml"))
r.Get("/signup", usersC.New)
r.Post("/users", usersC.Create)
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Page not found :", http.StatusNotFound)
})
fmt.Println("server start at port 3000")
http.ListenAndServe(":3001", r)
}