Setting up .env reader

This commit is contained in:
collin 2025-06-30 12:37:33 +02:00
parent 2341021744
commit 550c05e2e4
No known key found for this signature in database
6 changed files with 21 additions and 2 deletions

View file

@ -59,6 +59,8 @@ func SetupAuth() {
encoder.Close()
token = sb.String()
fmt.Println("auth ready")
}
func isAuthorized(r *http.Request) bool {
@ -114,13 +116,19 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
w.WriteHeader(http.StatusBadRequest)
return
}
attending := r.Form.Get("attending") == "true"
partySize, err := strconv.ParseInt(r.Form.Get("party-size"), 10, 1)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
partyMembers := make([]Member, partySize)
for i := range partySize {
name := r.Form.Get(fmt.Sprintf("name-%d", i))

View file

@ -20,7 +20,7 @@ func SetupDatabase() *sql.DB {
log.Fatal("failed to query database")
}
fmt.Println(version)
fmt.Println("database ready")
return db
}

View file

@ -10,4 +10,5 @@ require (
require (
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/joho/godotenv v1.5.1 // indirect
)

View file

@ -4,6 +4,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=

View file

@ -1,12 +1,16 @@
package main
import (
"fmt"
"net/http"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
)
func main() {
godotenv.Load(".env")
ntfy := SetupNtfyClient()
db := SetupDatabase()
@ -14,5 +18,7 @@ func main() {
SetupAuth()
hnd := &Handler{db, ntfy}
fmt.Println("handler ready")
http.ListenAndServe(":8000", hnd)
}

View file

@ -66,6 +66,8 @@ func SetupNtfyClient() *Ntfy {
log.Fatal(err)
}
fmt.Println("ntfy ready")
return &Ntfy{client: tp}
}