diff --git a/README.md b/README.md index c420693..d57f527 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Todo App with GO and HTMX +Goal: make a todo app with minimal reliance on other libraries and frameworks. + +I'll assume that it is a single user app so I do not have to worry about concurrent access, high throughput, +etc.. + ## Plan day 1 - [x] create Go webserver @@ -14,16 +19,17 @@ - [x] persist todos in redis - [x] spruce up + ## Plan day 2 -make it use only battery included features, +make it use only battery included features i.e. replace redis with an event driven approach - [x] modularize app - [x] replace redis with json stream - [x] use hashmap for fast individual access -- [ ] cache data to avoid reading each time -- [ ] create event store -- [ ] make events -- [ ] implement event store +- [x] cache data to avoid reading each time +- [x] create event store +- [x] make events +- [x] implement event store diff --git a/go.mod b/go.mod index 7243503..88257c6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module snamellit.com/play/todo -go 1.21.0 +go 1.21 diff --git a/internal/persist/persist.go b/internal/persist/persist.go index a7dba66..40ecb09 100644 --- a/internal/persist/persist.go +++ b/internal/persist/persist.go @@ -3,11 +3,11 @@ package persist import ( "encoding/json" "fmt" - "os" "io" -) + "os" -import "snamellit.com/play/todo/internal/model" + "snamellit.com/play/todo/internal/model" +) var EMPTY_TODO = model.Todo{Id: 0, Title: "", Completed: false} diff --git a/internal/webserver/webserver.go b/internal/webserver/webserver.go index 4b16e51..9bb289e 100644 --- a/internal/webserver/webserver.go +++ b/internal/webserver/webserver.go @@ -9,6 +9,10 @@ import ( ) +func PathHandleFunc(path string, f func(http.ResponseWriter, *http.Request)) { + http.Handle(path, http.StripPrefix(path, http.HandlerFunc(f))) +} + func IndexHandler(w http.ResponseWriter, r *http.Request) { t, _ := template.ParseFiles("templates/index.html") t.Execute(w, nil) diff --git a/main.go b/main.go index de40fa9..8142e10 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,8 @@ func main() { http.Handle("/static/", http.StripPrefix("/static/", fs)) http.HandleFunc("/", webserver.IndexHandler) http.HandleFunc("/todos", webserver.TodosHandler) - togglePath := "/toggle-todo/" - http.Handle(togglePath, http.StripPrefix(togglePath, http.HandlerFunc(webserver.ToggleTodoHandler))) - todoPath := "/todo/" - http.Handle(todoPath, http.StripPrefix(todoPath, http.HandlerFunc(webserver.TodoHandler))) + webserver.PathHandleFunc("/toggle-todo/", webserver.ToggleTodoHandler) + webserver.PathHandleFunc("/todo/", webserver.TodoHandler) log.Fatal(http.ListenAndServe(":8080", nil)) }