Search Apps Documentation Source Content File Folder Download Copy Actions Download

simplemsg.gno

0.73 Kb · 40 lines
 1package simplemsg
 2
 3var (
 4	lastMessage string
 5	callCount   int
 6)
 7
 8func SetMessage(message string) string {
 9	lastMessage = message
10	callCount++
11	return "message stored"
12}
13
14func GetMessage() (string, int) {
15	return lastMessage, callCount
16}
17
18func Render(_ string) string {
19	if callCount == 0 {
20		return "# Simple Message Realm\n\nNo message stored yet."
21	}
22	return "# Simple Message Realm\n\n- message: " + lastMessage + "\n- updates: " + itoa(callCount) + "\n"
23}
24
25// minimal int → string helper to avoid imports
26func itoa(n int) string {
27	if n == 0 {
28		return "0"
29	}
30	sign := ""
31	if n < 0 {
32		sign = "-"
33		n = -n
34	}
35	var digits []byte
36	for n > 0 {
37		digits = append([]byte{byte('0' + n%10)}, digits...)
38		n /= 10
39	}
40	return sign + string(digits)
41}