restructuring, config and readme

This commit is contained in:
u80864958
2025-04-29 14:57:48 +02:00
parent f027ee7e39
commit fc8b888198
19 changed files with 317 additions and 185 deletions

View File

@ -0,0 +1,9 @@
package model
type Login struct {
Name string `json:"name"`
Password string `json:"Password"`
}
type LoginResponse struct {
Token string `json:"token"`
}

View File

@ -0,0 +1,19 @@
package model
import (
"gorm.io/gorm"
)
type Post struct {
gorm.Model
ID uint `gorm:"primarykey" json:"id"`
Title string `json:"title"`
TLDR string `json:"tldr"`
Content string `json:"content"`
Comments []Comment
}
type Comment struct {
ID uint
PostID uint
Content string `json:"content"`
}

View File

@ -0,0 +1,36 @@
package model
import (
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func Init() *gorm.DB {
db, err := gorm.Open(sqlite.Open("./blog.db"))
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Post{}, &Comment{})
db.Save(&Post{
ID: 1,
Title: "Hello World",
TLDR: "introduction to ng-blog",
Content: `
## Welcome
This is ng-blog, your simple blog written in Angular and Golang.
### Login
The default login is:
> Username: admin
>
> Password: admin
`,
})
return db
}