Search Apps Documentation Source Content File Folder Download Copy Actions Download

blog.gno

0.74 Kb · 41 lines
 1package custom_resource
 2
 3import (
 4	"time"
 5)
 6
 7type Post struct {
 8	Title   string
 9	Content string
10	Created time.Time
11	Creator string // id of the creator, address or pkg path
12}
13
14type Blog struct {
15	Post []Post
16}
17
18func (a *Blog) NewPost(title string, content string) {
19	newPost := Post{
20		Title:   title,
21		Content: content,
22		Created: time.Now(),
23		Creator: daoPrivate.CallerID(),
24	}
25	a.Post = append(a.Post, newPost)
26}
27
28func (a *Blog) Render() string {
29	s := ""
30	if len(a.Post) == 0 {
31		return "No post available"
32	}
33	for i := 0; i < len(a.Post); i++ {
34		s += "## " + a.Post[i].Title + "\n\n"
35		s += " " + a.Post[i].Content + "\n\n"
36		s += a.Post[i].Created.Format("15h04 02/01/2006")
37		s += " - " + a.Post[i].Creator + "\n\n"
38		s += "---\n"
39	}
40	return s
41}