Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

blog.gno

0.98 Kb · 44 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
18// The realm is threaded in from the action handler, which receives the DAO's
19// own. It is last because the VM reads a leading realm parameter as a crossing
20// function, and receivers do not exempt a method from that rule.
21func (a *Blog) NewPost(title string, content string, rlm realm) {
22	newPost := Post{
23		Title:   title,
24		Content: content,
25		Created: time.Now(),
26		Creator: daoPrivate.CallerID(daoPrivate, rlm),
27	}
28	a.Post = append(a.Post, newPost)
29}
30
31func (a *Blog) Render() string {
32	s := ""
33	if len(a.Post) == 0 {
34		return "No post available"
35	}
36	for i := 0; i < len(a.Post); i++ {
37		s += "## " + a.Post[i].Title + "\n\n"
38		s += " " + a.Post[i].Content + "\n\n"
39		s += a.Post[i].Created.Format("15h04 02/01/2006")
40		s += " - " + a.Post[i].Creator + "\n\n"
41		s += "---\n"
42	}
43	return s
44}