Search Apps Documentation Source Content File Folder Download Copy Actions Download

simplemsgs.gno

0.69 Kb ยท 39 lines
 1package simplemsgs
 2
 3var (
 4	lastMessage string
 5	callCount   int
 6)
 7
 8func SetMessage(_ realm, 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
25func itoa(n int) string {
26	if n == 0 {
27		return "0"
28	}
29	sign := ""
30	if n < 0 {
31		sign = "-"
32		n = -n
33	}
34	var digits []byte
35	for n > 0 {
36		digits = append([]byte{byte('0' + n%10)}, digits...)
37		n /= 10
38	}
39	return sign + string(digits)
40}