Search Apps Documentation Source Content File Folder Download Copy Actions Download

types.gno

0.72 Kb ยท 27 lines
 1package minisocial
 2
 3import (
 4	// The standard Gno package
 5	"time" // For handling time operations
 6
 7	"gno.land/p/nt/ufmt" // For string formatting, like `fmt`
 8)
 9
10// Post defines the main data we keep about each post
11type Post struct {
12	text      string    // Main text body
13	author    address   // Address of the post author, provided by the execution context
14	createdAt time.Time // When the post was created
15}
16
17// String stringifies a Post
18func (p Post) String() string {
19	out := p.text
20	out += "\n\n"
21	out += ufmt.Sprintf("_by %s_, ", p.author)
22	// We can use `ufmt` to format strings, and the built-in time library formatting function
23	out += ufmt.Sprintf("_on %s_", p.createdAt.Format("02 Jan 2006, 15:04"))
24
25	out += "\n\n"
26	return out
27}