Change the project layout
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch file",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "debug",
|
||||||
|
"program": "main.go"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1 +1,13 @@
|
|||||||
#
|
# Blog_Software
|
||||||
|
An easy to use blogging software. That's it.
|
||||||
|
|
||||||
|
## V1 goals
|
||||||
|
- Multi-user support
|
||||||
|
- Markdown publishing
|
||||||
|
|
||||||
|
## Longer-term goals
|
||||||
|
- Extreme customization
|
||||||
|
- Single-user ability
|
||||||
|
- Markdown previewer/editor
|
||||||
|
- Obsidian.md publishing/extension
|
||||||
|
-
|
||||||
@@ -2,8 +2,8 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"os"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckError(e error) {
|
func CheckError(e error) {
|
||||||
@@ -12,7 +12,7 @@ func CheckError(e error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(db *sql.DB, migrations []string) {
|
func Migrate(db *sql.DB, migrations []string) {
|
||||||
for _, x := range migrations {
|
for _, x := range migrations {
|
||||||
data, err := os.ReadFile("./db/migrations/" + x + ".sql")
|
data, err := os.ReadFile("./db/migrations/" + x + ".sql")
|
||||||
CheckError(err)
|
CheckError(err)
|
||||||
@@ -21,4 +21,4 @@ func Update(db *sql.DB, migrations []string) {
|
|||||||
CheckError(err)
|
CheckError(err)
|
||||||
log.Print("Applied migration " + x)
|
log.Print("Applied migration " + x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
dbpkg "nkeller.dev/blog_software/db"
|
||||||
|
usrpkg "nkeller.dev/blog_software/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
id int
|
||||||
|
created_at int
|
||||||
|
creator_id int
|
||||||
|
title string
|
||||||
|
description string
|
||||||
|
content string
|
||||||
|
tags string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// DB and Migrations
|
||||||
|
db, err := sql.Open("sqlite3", "./db/blogging.db")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
migrations := [...]string{
|
||||||
|
"1784776258",
|
||||||
|
}
|
||||||
|
dbpkg.Migrate(db, migrations[:])
|
||||||
|
|
||||||
|
user, err := usrpkg.Create(db, "profilelag2", "Hello")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(user)
|
||||||
|
fmt.Printf("user: %v\n", user)
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
package post
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package post
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package post
|
||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
dbpkg "nkeller.dev/blog_software/src/db"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
ID int
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// DB and Migrations
|
|
||||||
db, err := sql.Open("sqlite3", "./db/blogging.db")
|
|
||||||
dbpkg.CheckError(err)
|
|
||||||
defer db.Close()
|
|
||||||
migrations := [...]string{
|
|
||||||
"1784776258",
|
|
||||||
}
|
|
||||||
dbpkg.Update(db, migrations[:])
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
id int
|
||||||
|
created_at time.Time
|
||||||
|
name sql.NullString
|
||||||
|
username string
|
||||||
|
password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Create(db *sql.DB, username string, password string) (*User, error) {
|
||||||
|
//TODO: Hash password, plaintext is dumb and unsafe
|
||||||
|
row := db.QueryRow("INSERT INTO users(username, password) VALUES (?, ?) RETURNING id, created_at, name, username;", username, password)
|
||||||
|
user := &User{}
|
||||||
|
err := row.Scan(&user.id, &user.created_at, &user.name, &user.username)
|
||||||
|
return user, err
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
dbpkg "nkeller.dev/blog_software/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Delete(db *sql.DB, id int) {
|
||||||
|
result, err := db.Exec("DELETE FROM users WHERE id = ?;", id)
|
||||||
|
dbpkg.CheckError(err)
|
||||||
|
_ = result
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
Reference in New Issue
Block a user