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
+1
View File
@@ -14,6 +14,7 @@ require (
github.com/go-webauthn/x v0.1.9 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/google/go-tpm v0.9.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.21.0 // indirect
+2
View File
@@ -24,6 +24,8 @@ github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47QWKfU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+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
}