Bump to go 1.22

This commit is contained in:
Andrew-71 2024-03-18 19:33:57 +03:00
parent 065e674d39
commit fd9c2a1b95
5 changed files with 15 additions and 10 deletions

View file

@ -26,4 +26,7 @@ data
| ... | ...
+-- log.txt +-- log.txt
+-- readme.txt +-- readme.txt
config
+-- config.txt
``` ```

View file

@ -5,8 +5,9 @@ List of things to add to this project
* Add export feature * Add export feature
* Add missing frontend pages * Add missing frontend pages
## Long-medium term ## Long-medium term considerations
* *Go* dependency-less * Improve logging, log to files
* Improve (add?) logging, log to files
* Make the CLI better * Make the CLI better
* Timezones? * Think about timezones
* Consider more secure auth methods
* *Go* dependency-less? <-- this is a terrible idea

View file

@ -6,11 +6,11 @@ import (
"net/http" "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 // 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) // 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? // 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) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if ok { if ok {

2
go.mod
View file

@ -1,5 +1,5 @@
module hibiscus module hibiscus
go 1.20 go 1.22
require github.com/go-chi/chi/v5 v5.0.12 require github.com/go-chi/chi/v5 v5.0.12

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware" "github.com/go-chi/chi/v5/middleware"
"log"
"net/http" "net/http"
"strconv" "strconv"
) )
@ -11,7 +12,7 @@ import (
func Serve() { func Serve() {
r := chi.NewRouter() r := chi.NewRouter()
r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes) 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) { r.NotFound(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404) w.WriteHeader(404)
http.ServeFile(w, r, "./pages/error/404.html") http.ServeFile(w, r, "./pages/error/404.html")
@ -43,8 +44,8 @@ func Serve() {
// Static files // Static files
fs := http.FileServer(http.Dir("public")) 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) fmt.Println("Website working on port: ", Cfg.Port)
_ = http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r) log.Fatal(http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r))
} }