realm.gno

0.42 Kb ยท 25 lines
 1package microposts
 2
 3import (
 4	"std"
 5	"strconv"
 6	"time"
 7)
 8
 9var posts []*Post
10
11func CreatePost(text string) {
12	posts = append(posts, &Post{
13		text:      text,
14		author:    std.PreviousRealm().Address(), // provided by env
15		createdAt: time.Now(),
16	})
17}
18
19func Render(_ string) string {
20	out := "# Posts\n"
21	for i := len(posts) - 1; i >= 0; i-- {
22		out += "### Post " + strconv.Itoa(i) + "\n" + posts[i].String()
23	}
24	return out
25}