more db stuff

This commit is contained in:
2026-08-09 05:30:55 -07:00
parent ca4733fcae
commit 891f089d31
3 changed files with 21 additions and 4 deletions
+18 -4
View File
@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/joho/godotenv"
)
var (
@@ -42,10 +43,15 @@ type PasskeyStore interface {
func main() {
l = log.Default()
godotenv.Load()
proto := getEnv("PROTO", "http")
host := getEnv("HOST", "localhost")
port := getEnv("PORT", ":8080")
port := ":" + getEnv("PORT", "8080")
origin := fmt.Sprintf("%s://%s%s", proto, host, port)
dbUser := getEnv("DB_USER")
dbPassword := getEnv("DB_PASSWORD")
dbName := getEnv("DB_NAME")
l.Printf("[INFO] make webauthn config")
wconfig := &webauthn.Config{
@@ -56,10 +62,19 @@ func main() {
l.Printf("[INFO] create webauthn")
if webAuthn, err = webauthn.New(wconfig); err != nil {
fmt.Printf("[FATA] %s", err.Error())
fmt.Printf("[FATAL] %s", err.Error())
os.Exit(1)
}
db, err := sql.Open("mysql", dbUser + ":" + dbPassword + "@/")
if err != nil {
panic(err)
}
// See "Important settings" section.
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
l.Printf("[INFO] create datastore")
datastore = NewInMem(l)
@@ -67,7 +82,7 @@ func main() {
// Serve the web files
http.Handle("/", http.FileServer(http.Dir("./web")))
// Add auth the routes
// Add auth routes
http.HandleFunc("/api/passkey/registerStart", BeginRegistration)
http.HandleFunc("/api/passkey/registerFinish", FinishRegistration)
http.HandleFunc("/api/passkey/loginStart", BeginLogin)
@@ -154,7 +169,6 @@ func FinishRegistration(w http.ResponseWriter, r *http.Request) {
})
l.Printf(msg)
JSONResponse(w, msg, http.StatusBadRequest)
return
}