10 changed files with 114 additions and 13 deletions
@ -1,20 +1,35 @@ |
|||||||
package main |
package main |
||||||
|
|
||||||
import "time" |
import ( |
||||||
|
"time" |
||||||
|
|
||||||
type remind struct { |
"gorm.io/gorm" |
||||||
ID int `json:"id"` |
) |
||||||
|
|
||||||
|
type Remind struct { |
||||||
|
ID int `json:"id" gorm:"primary_key"` |
||||||
Title string `json:"title"` |
Title string `json:"title"` |
||||||
DateTime time.Time `json:"datetime"` |
DateTime time.Time `json:"datetime" gorm:"index"` |
||||||
Content string `json:"content"` |
Content string `json:"content"` |
||||||
} |
} |
||||||
|
|
||||||
var remindList = []remind{ |
// Return a list of all the articles
|
||||||
remind{ID: 1, Title: "Remind 1", DateTime: time.Now(), Content: "Remind 1 body"}, |
func getAllReminds() ([]Remind, error) { |
||||||
remind{ID: 2, Title: "Remind 2", DateTime: time.Now(), Content: "Remind 2 body"}, |
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 FirstRemindInit(db *gorm.DB) { |
||||||
func getAllReminds() []remind { |
r := []Remind{ |
||||||
return remindList |
{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 @@ |
|||||||
|
<!--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 @@ |
|||||||
|
<!--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