resolve.gno

1.07 Kb ยท 40 lines
 1package use_rsysusers
 2
 3import (
 4	"gno.land/r/sys/users" // Import the user registry
 5)
 6
 7func Render(path string) string {
 8	out := "# Username checker\n\n"
 9
10	// Default render
11	if path == "" {
12		out += `This is short example on how developers can use the gno.land user registry to resolve
13usernames and addresses in their realms. Check out the example below.
14
15---
16
17`
18		out += "Add `:{name OR address}` to the search bar to check for a name or address.\n\n"
19		out += "Here are some examples:\n\n"
20		out += "- [@test1](/r/docs/users:test1)\n"
21		out += "- [g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5](/r/docs/users:g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5)\n"
22
23		return out
24	}
25
26	// Try to resolve the search input in the registry
27	data, _ := users.ResolveAny(path)
28	if data != nil {
29		out += "## Found the user you're looking for: "
30		// RenderLink will return a clickable gnoweb link leading to the user's page
31		out += data.RenderLink("")
32		return out
33	}
34
35	// Note: the above can be done with known inputs as well, ie ResolveName & ResolveAddress.
36
37	out += "## Didn't find that user :/"
38
39	return out
40}