summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-14 00:20:44 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-04-14 00:20:44 +0200
commit92d6bc8db541582982ee38fd62f16f63efceb559 (patch)
tree4817313bbdfb60ca37f389eafe726cb87001eac9
parentd6d54abb48f061128efc16081a270c5adaa8a43f (diff)
WIP: User table
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--model/uuid.go2
-rw-r--r--timer.go30
4 files changed, 30 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index b16882b..ec76474 100644
--- a/go.mod
+++ b/go.mod
@@ -6,4 +6,5 @@ require (
github.com/a-h/templ v0.2.648 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
+ golang.org/x/crypto v0.22.0 // indirect
)
diff --git a/go.sum b/go.sum
index 51e2090..47951cd 100644
--- a/go.sum
+++ b/go.sum
@@ -4,3 +4,5 @@ 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/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
+golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
+golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
diff --git a/model/uuid.go b/model/uuid.go
index 8852cc8..4a25e41 100644
--- a/model/uuid.go
+++ b/model/uuid.go
@@ -10,7 +10,7 @@ type UUID struct {
}
func MakeUUID() UUID {
- id, _ := uuid.NewRandom()
+ id, _ := uuid.NewV7()
return UUID { payload: id }
}
diff --git a/timer.go b/timer.go
index ee82a30..7882a11 100644
--- a/timer.go
+++ b/timer.go
@@ -1,18 +1,21 @@
package main
import (
+ "context"
+ "database/sql"
"log"
"net/http"
- "database/sql"
- "context"
+ "strconv"
"strings"
"time"
- "strconv"
+ "golang.org/x/crypto/bcrypt"
+
+ "github.com/google/uuid"
_ "github.com/mattn/go-sqlite3"
- "stevenlr.com/timer/view"
"stevenlr.com/timer/model"
+ "stevenlr.com/timer/view"
)
func insertTimer(tx *sql.Tx, name string, seconds int) error {
@@ -49,6 +52,17 @@ func initializeDatabase(db *sql.DB) error {
err = insertTimer(tx, "My timer2", 600)
if err != nil { return err }
+ _, err = tx.Exec(`
+ CREATE TABLE User (
+ Id BLOB NOT NULL UNIQUE,
+ Name TEXT NOT NULL,
+ StartTime TEXT NOT NULL,
+ EndTime TEXT NOT NULL,
+ PRIMARY KEY (id)
+ )
+ `)
+ if err != nil { return err }
+
return tx.Commit()
}
@@ -171,6 +185,14 @@ func (server* MyServer) handlePutTimer(w http.ResponseWriter, r *http.Request) {
}
func main() {
+ saltUuid, _ := uuid.NewRandom()
+ salt := saltUuid.String()
+ log.Println(salt)
+ bytes, _ := bcrypt.GenerateFromPassword([]byte(salt + "Hello, world!"), 12)
+ log.Println(bytes)
+}
+
+func main2() {
log.Println("Starting...")
db, err := sql.Open("sqlite3", ":memory:")