refactor routing, update readme
This commit is contained in:
parent
4dd320b9b0
commit
c1d73ca8b5
5 changed files with 21 additions and 13 deletions
16
README.md
16
README.md
|
@ -1,5 +1,10 @@
|
||||||
# Todo App with GO and HTMX
|
# 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
|
## Plan day 1
|
||||||
|
|
||||||
- [x] create Go webserver
|
- [x] create Go webserver
|
||||||
|
@ -14,16 +19,17 @@
|
||||||
- [x] persist todos in redis
|
- [x] persist todos in redis
|
||||||
- [x] spruce up
|
- [x] spruce up
|
||||||
|
|
||||||
|
|
||||||
## Plan day 2
|
## 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
|
i.e. replace redis with an event driven approach
|
||||||
|
|
||||||
- [x] modularize app
|
- [x] modularize app
|
||||||
- [x] replace redis with json stream
|
- [x] replace redis with json stream
|
||||||
- [x] use hashmap for fast individual access
|
- [x] use hashmap for fast individual access
|
||||||
- [ ] cache data to avoid reading each time
|
- [x] cache data to avoid reading each time
|
||||||
- [ ] create event store
|
- [x] create event store
|
||||||
- [ ] make events
|
- [x] make events
|
||||||
- [ ] implement event store
|
- [x] implement event store
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
||||||
module snamellit.com/play/todo
|
module snamellit.com/play/todo
|
||||||
|
|
||||||
go 1.21.0
|
go 1.21
|
||||||
|
|
|
@ -3,11 +3,11 @@ package persist
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"io"
|
"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}
|
var EMPTY_TODO = model.Todo{Id: 0, Title: "", Completed: false}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
t, _ := template.ParseFiles("templates/index.html")
|
t, _ := template.ParseFiles("templates/index.html")
|
||||||
t.Execute(w, nil)
|
t.Execute(w, nil)
|
||||||
|
|
6
main.go
6
main.go
|
@ -14,10 +14,8 @@ func main() {
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||||
http.HandleFunc("/", webserver.IndexHandler)
|
http.HandleFunc("/", webserver.IndexHandler)
|
||||||
http.HandleFunc("/todos", webserver.TodosHandler)
|
http.HandleFunc("/todos", webserver.TodosHandler)
|
||||||
togglePath := "/toggle-todo/"
|
webserver.PathHandleFunc("/toggle-todo/", webserver.ToggleTodoHandler)
|
||||||
http.Handle(togglePath, http.StripPrefix(togglePath, http.HandlerFunc(webserver.ToggleTodoHandler)))
|
webserver.PathHandleFunc("/todo/", webserver.TodoHandler)
|
||||||
todoPath := "/todo/"
|
|
||||||
http.Handle(todoPath, http.StripPrefix(todoPath, http.HandlerFunc(webserver.TodoHandler)))
|
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue