mirror.gno

0.49 Kb ยท 33 lines
 1package mirror
 2
 3import (
 4	"gno.land/p/demo/avl"
 5)
 6
 7var store avl.Tree
 8
 9func Register(pkgpath string, rndr func(string) string) {
10	if store.Has(pkgpath) {
11		return
12	}
13
14	if rndr == nil {
15		return
16	}
17
18	store.Set(pkgpath, rndr)
19}
20
21func Render(path string) string {
22	if raw, ok := store.Get(path); ok {
23		return raw.(func(string) string)("")
24	}
25
26	if store.Size() == 0 {
27		return "None are fair."
28	}
29
30	return "Mirror, mirror on the wall, which realm's the fairest of them all?"
31}
32
33// Credits to @jeronimoalbi