Remove unused title field
This commit is contained in:
parent
99d20cf1f6
commit
645756d800
12
db.go
12
db.go
|
@ -20,12 +20,12 @@ func initializeDatabase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeToDB(post BlogPost) {
|
func writeToDB(post BlogPost) {
|
||||||
stmt, _ := db.Prepare("INSERT INTO blogposts(author, title, content, time) VALUES (?, ?, ?, ?)")
|
stmt, _ := db.Prepare("INSERT INTO blogposts(author, content, time) VALUES (?, ?, ?)")
|
||||||
stmt.Exec(post.Author, post.Title, post.Content, time.Now().Unix())
|
stmt.Exec(post.Author, post.Content, time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBlogpostsFromDB() []BlogPost {
|
func readBlogpostsFromDB() []BlogPost {
|
||||||
res, err := db.Query("SELECT content, author, title, time from blogposts")
|
res, err := db.Query("SELECT content, title, time from blogposts limit 50")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error reading blogposts")
|
log.Println("Error reading blogposts")
|
||||||
return make([]BlogPost, 0)
|
return make([]BlogPost, 0)
|
||||||
|
@ -38,10 +38,10 @@ func resultToBlogposts(res *sql.Rows) []BlogPost {
|
||||||
defer res.Close()
|
defer res.Close()
|
||||||
entries := make([]BlogPost, 0)
|
entries := make([]BlogPost, 0)
|
||||||
for res.Next() {
|
for res.Next() {
|
||||||
var content, author, title string
|
var content, author string
|
||||||
var timeInt int64
|
var timeInt int64
|
||||||
res.Scan(&content, &author, &title, &timeInt)
|
res.Scan(&content, &author, &timeInt)
|
||||||
post := BlogPost{Content:content, Author:author, Title:title, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")}
|
post := BlogPost{Content:content, Author:author, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")}
|
||||||
entries = append(entries, post)
|
entries = append(entries, post)
|
||||||
}
|
}
|
||||||
return entries
|
return entries
|
||||||
|
|
1
main.go
1
main.go
|
@ -16,7 +16,6 @@ func main() {
|
||||||
type BlogPost struct {
|
type BlogPost struct {
|
||||||
Id int64 `"id"`
|
Id int64 `"id"`
|
||||||
Content string `"content"`
|
Content string `"content"`
|
||||||
Title string `"title"`
|
|
||||||
Author string `"author"`
|
Author string `"author"`
|
||||||
Secret string `"secret"`
|
Secret string `"secret"`
|
||||||
Time time.Time `"time"`
|
Time time.Time `"time"`
|
||||||
|
|
2
schema
2
schema
|
@ -1 +1 @@
|
||||||
CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `title` text NULL, `content` text null, `time` time null);
|
CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `content` text null, `time` time null);
|
||||||
|
|
2
test.sh
2
test.sh
|
@ -5,5 +5,5 @@ else
|
||||||
msg="$1"
|
msg="$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Title\": \"title\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v
|
curl localhost:12345/add -d "{\"content\": \"$msg\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user