Setting up .env reader
This commit is contained in:
parent
7b70cb5f2c
commit
350952b2fe
6 changed files with 21 additions and 2 deletions
|
|
@ -59,6 +59,8 @@ func SetupAuth() {
|
||||||
encoder.Close()
|
encoder.Close()
|
||||||
|
|
||||||
token = sb.String()
|
token = sb.String()
|
||||||
|
|
||||||
|
fmt.Println("auth ready")
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAuthorized(r *http.Request) bool {
|
func isAuthorized(r *http.Request) bool {
|
||||||
|
|
@ -114,13 +116,19 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
attending := r.Form.Get("attending") == "true"
|
attending := r.Form.Get("attending") == "true"
|
||||||
partySize, err := strconv.ParseInt(r.Form.Get("party-size"), 10, 1)
|
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)
|
partyMembers := make([]Member, partySize)
|
||||||
for i := range partySize {
|
for i := range partySize {
|
||||||
name := r.Form.Get(fmt.Sprintf("name-%d", i))
|
name := r.Form.Get(fmt.Sprintf("name-%d", i))
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func SetupDatabase() *sql.DB {
|
||||||
log.Fatal("failed to query database")
|
log.Fatal("failed to query database")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(version)
|
fmt.Println("database ready")
|
||||||
|
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,5 @@ require (
|
||||||
require (
|
require (
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
|
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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/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 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
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/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 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
||||||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
godotenv.Load(".env")
|
||||||
|
|
||||||
ntfy := SetupNtfyClient()
|
ntfy := SetupNtfyClient()
|
||||||
|
|
||||||
db := SetupDatabase()
|
db := SetupDatabase()
|
||||||
|
|
@ -14,5 +18,7 @@ func main() {
|
||||||
|
|
||||||
SetupAuth()
|
SetupAuth()
|
||||||
hnd := &Handler{db, ntfy}
|
hnd := &Handler{db, ntfy}
|
||||||
|
fmt.Println("handler ready")
|
||||||
|
|
||||||
http.ListenAndServe(":8000", hnd)
|
http.ListenAndServe(":8000", hnd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ func SetupNtfyClient() *Ntfy {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("ntfy ready")
|
||||||
|
|
||||||
return &Ntfy{client: tp}
|
return &Ntfy{client: tp}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue