Gno.land for Go Developers
Building Your App in Web3 -- Getting to Gno
5 June 2023
Manfred Touron
VP Eng., Gno.land
Manfred Touron
VP Eng., Gno.land
package demo func Hello(name string) string { return "Hello " + name + "!" }
var x int func Incr() { x += 1 }
func greetings(name string) string { // private return "Welcome, " + name + "!" } func Render(path string) string { switch { case path == "hello": return "world!" case strings.HasPrefix(path, "greetings/"): name := strings.Split(path, "/")[1] // take string after slash name = strings.Title(name) // capitalize first letter return greetings(name) } return "404" }
import ( "gno.land/p/demo/avl" "gno.land/p/demo/dom" ) func Render(path string) string { thread := dom.Plot{Name: "Hello!"} thread.AddPost("Foo", "foo foo foo") thread.AddPost("Bar", "bar bar bar") return thread.String() }
import ( "gno.land/p/demo/grc/grc20" ) var Token *grc20.Token func init() { minter := grc20.NewAdminToken("Foo", "FOO", 4) minter.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10_000*10_000) Token = minter.GRC20() // expose an unprivileged token }
// A Post is a "thread" or a "reply" depending on context. // A thread is a Post of a Board that holds other replies. type Post struct { board *Board id PostID creator std.Address title string // optional body string replies avl.Tree // Post.id -> *Post repliesAll avl.Tree // Post.id -> *Post (all replies, for top-level posts) reposts avl.Tree // Board.id -> Post.id threadID PostID // original Post.id parentID PostID // parent Post.id (if reply or repost) repostBoard BoardID // original Board.id (if repost) createdAt time.Time updatedAt time.Time }
# install the "gno" CLI $> git clone git@github.com:gnolang/gno.git $> cd ./gno $> make install_gno # run test $> gno test --verbose . === RUN TestPackage --- PASS: TestPackage (0.01s) ok ./. 0.50s
______ ____ ____ __ / ____/___ _____ ___ ___ ____ / __/ / __ \___ ____ _/ /___ ___ _____ / / __/ __ `/ __ `__ \/ _ \ / __ \/ /_ / /_/ / _ \/ __ `/ / __ `__ \/ ___/ / /_/ / /_/ / / / / / / __/ / /_/ / __/ / _, _/ __/ /_/ / / / / / / (__ ) \____/\__,_/_/ /_/ /_/\___/ \____/_/ /_/ |_|\___/\__,_/_/_/ /_/ /_/____/