aboutsummaryrefslogtreecommitdiff
path: root/cmd/parser
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/parser')
-rw-r--r--cmd/parser/main.go37
1 files changed, 2 insertions, 35 deletions
diff --git a/cmd/parser/main.go b/cmd/parser/main.go
index 6d3c3c4..3d0b132 100644
--- a/cmd/parser/main.go
+++ b/cmd/parser/main.go
@@ -16,7 +16,7 @@ import (
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
- "golang.org/x/crypto/bcrypt"
+ "paterissa.net/mblog/internal"
_ "github.com/jackc/pgx/v5/stdlib"
)
@@ -121,40 +121,7 @@ func main() {
}
defer db.Close()
- _, table_check := db.Query("SELECT * FROM posts;")
- if table_check != nil {
- _, err = db.Exec("CREATE TABLE posts (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, content TEXT NOT NULL);")
- if err != nil {
- fmt.Fprintf(os.Stderr, "Unable to create posts table: %v\n", err)
- os.Exit(1)
- }
- }
-
- webmaster := os.Getenv("webmaster")
- passOne := os.Getenv("blog_pass1")
- passTwo := os.Getenv("blog_pass2")
-
- _, table_check = db.Query("SELECT * FROM logins;")
- if table_check != nil {
- _, err = db.Exec("CREATE TABLE logins (id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, time DATE DEFAULT CURRENT_DATE, pass_one TEXT NOT NULL, pass_two TEXT NOT NULL);")
- if err != nil {
- fmt.Fprintf(os.Stderr, "Unable to create logins table: %v\n", err)
- os.Exit(1)
- }
-
- hashOne, errHashOne := bcrypt.GenerateFromPassword([]byte(passOne), 12)
- hashTwo, errHashTwo := bcrypt.GenerateFromPassword([]byte(passTwo), 12)
- if errHashOne != nil || errHashTwo != nil {
- fmt.Fprintf(os.Stderr, "Failed to hash password")
- os.Exit(1)
- }
-
- _, err = db.Exec(fmt.Sprintf("INSERT INTO logins (name, pass_one, pass_two) VALUES ('%s', '%s', '%s');", webmaster, hashOne, hashTwo))
- if err != nil {
- fmt.Fprintf(os.Stderr, "Unable to add webmaster to logins table: %v\n", err)
- os.Exit(1)
- }
- }
+ internal.Migrate(db, os.Getenv("webmaster"), os.Getenv("blog_pass1"), os.Getenv("blog_pass2"))
router := http.NewServeMux()
router.HandleFunc("/", mdServe)