mirror of
https://github.com/ducky-labs/htmx-go-todo.git
synced 2026-02-04 06:31:00 +00:00
Initial commit
This commit is contained in:
30
main.go
Normal file
30
main.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := openDB()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer closeDB()
|
||||
err = setupDB()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger)
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
||||
r.Get("/", func(w http.ResponseWriter, _ *http.Request) {
|
||||
tmpl, _ := template.New("").ParseFiles("templates/index.html")
|
||||
tmpl.ExecuteTemplate(w, "Base", nil)
|
||||
})
|
||||
http.ListenAndServe("localhost:3000", r)
|
||||
}
|
||||
Reference in New Issue
Block a user