10 changed files with 114 additions and 13 deletions
@ -1,20 +1,35 @@
@@ -1,20 +1,35 @@
|
||||
package main |
||||
|
||||
import "time" |
||||
import ( |
||||
"time" |
||||
|
||||
type remind struct { |
||||
ID int `json:"id"` |
||||
"gorm.io/gorm" |
||||
) |
||||
|
||||
type Remind struct { |
||||
ID int `json:"id" gorm:"primary_key"` |
||||
Title string `json:"title"` |
||||
DateTime time.Time `json:"datetime"` |
||||
DateTime time.Time `json:"datetime" gorm:"index"` |
||||
Content string `json:"content"` |
||||
} |
||||
|
||||
var remindList = []remind{ |
||||
remind{ID: 1, Title: "Remind 1", DateTime: time.Now(), Content: "Remind 1 body"}, |
||||
remind{ID: 2, Title: "Remind 2", DateTime: time.Now(), Content: "Remind 2 body"}, |
||||
// Return a list of all the articles
|
||||
func getAllReminds() ([]Remind, error) { |
||||
var reminds []Remind |
||||
result := DB.Find(&reminds) |
||||
if err := result.Error; err != nil { |
||||
return nil, err |
||||
} |
||||
return reminds, nil |
||||
} |
||||
|
||||
// Return a list of all the articles
|
||||
func getAllReminds() []remind { |
||||
return remindList |
||||
func FirstRemindInit(db *gorm.DB) { |
||||
r := []Remind{ |
||||
{ID: 1, Title: "Remind 1", DateTime: time.Now(), Content: "Remind 1 body"}, |
||||
{ID: 2, Title: "Remind 2", DateTime: time.Now(), Content: "Remind 2 body"}, |
||||
} |
||||
result := db.Create(&r) |
||||
if result.RowsAffected == 0 { |
||||
panic("Not inserted test remind!") |
||||
} |
||||
} |
||||
|
||||
Binary file not shown.
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
<!--404.html--> |
||||
|
||||
<!--Embed the header.html template at this location--> |
||||
{{ template "header.html" .}} |
||||
|
||||
<!--Loop over the `payload` variable, which is the list of articles--> |
||||
<h2>{{.title}}</h2> |
||||
<p>{{.error}}</p> |
||||
|
||||
<!--Embed the footer.html template at this location--> |
||||
{{ template "footer.html" .}} |
||||
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
<!--index.html--> |
||||
|
||||
<!--Embed the header.html template at this location--> |
||||
{{ template "header.html" .}} |
||||
|
||||
<!--Loop over the `payload` variable, which is the list of articles--> |
||||
<h2>{{.payload.Title}}</h2> |
||||
<p>Создано: {{.payload.DateTime.Format "Jan 02, 2006 15:04:05"}}</p> |
||||
<!--Display the content of the article--> |
||||
<p>Описание: {{.payload.Content}}</p> |
||||
|
||||
<!--Embed the footer.html template at this location--> |
||||
{{ template "footer.html" .}} |
||||
Loading…
Reference in new issue