Bump to go 1.22
This commit is contained in:
parent
065e674d39
commit
fd9c2a1b95
5 changed files with 15 additions and 10 deletions
|
@ -26,4 +26,7 @@ data
|
|||
| ...
|
||||
+-- log.txt
|
||||
+-- readme.txt
|
||||
|
||||
config
|
||||
+-- config.txt
|
||||
```
|
9
TODO.md
9
TODO.md
|
@ -5,8 +5,9 @@ List of things to add to this project
|
|||
* Add export feature
|
||||
* Add missing frontend pages
|
||||
|
||||
## Long-medium term
|
||||
* *Go* dependency-less
|
||||
* Improve (add?) logging, log to files
|
||||
## Long-medium term considerations
|
||||
* Improve logging, log to files
|
||||
* Make the CLI better
|
||||
* Timezones?
|
||||
* Think about timezones
|
||||
* Consider more secure auth methods
|
||||
* *Go* dependency-less? <-- this is a terrible idea
|
4
auth.go
4
auth.go
|
@ -6,11 +6,11 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
// This middleware handles authentication & authorization for the app.
|
||||
// BasicAuth is a middleware that handles authentication & authorization for the app.
|
||||
// It uses BasicAuth because I doubt there is a need for something sophisticated in a small hobby project
|
||||
// Originally taken from https://www.alexedwards.net/blog/basic-authentication-in-go (13.03.2024)
|
||||
// TODO: why did I have to convert Handler from HandlerFunc?
|
||||
func basicAuth(next http.Handler) http.Handler {
|
||||
func BasicAuth(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
username, password, ok := r.BasicAuth()
|
||||
if ok {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,5 +1,5 @@
|
|||
module hibiscus
|
||||
|
||||
go 1.20
|
||||
go 1.22
|
||||
|
||||
require github.com/go-chi/chi/v5 v5.0.12
|
||||
|
|
7
serve.go
7
serve.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -11,7 +12,7 @@ import (
|
|||
func Serve() {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes)
|
||||
r.Use(basicAuth) // TODO: ..duh!
|
||||
r.Use(BasicAuth) // TODO: is this good enough?
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(404)
|
||||
http.ServeFile(w, r, "./pages/error/404.html")
|
||||
|
@ -43,8 +44,8 @@ func Serve() {
|
|||
|
||||
// Static files
|
||||
fs := http.FileServer(http.Dir("public"))
|
||||
r.Handle("/public/*", http.StripPrefix("/public/", fs))
|
||||
r.Handle("/public/", http.StripPrefix("/public/", fs))
|
||||
|
||||
fmt.Println("Website working on port: ", Cfg.Port)
|
||||
_ = http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r)
|
||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue