1package permissions23import (4 "errors"56 "gno.land/p/gnoland/boards/v0"7)89// Example user account10const user address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"1112// Define a role13const RoleExample boards.Role = "example"1415// Define a permission16const PermissionFoo boards.Permission = 421718func ExamplePermission() {19 // Define a custom foo permission validation function20 validateFoo := func(_ boards.Permissions, args boards.Args) error {21 // Check that the first argument is the string "bob"22 if name, ok := args[0].(string); !ok || name != "bob" {23 return errors.New("unauthorized")24 }25 return nil26 }2728 // Create a permissions instance and assign the custom validator to it29 perms := New()30 perms.ValidateFunc(PermissionFoo, validateFoo)3132 // Add foo permission to example role33 perms.AddRole(RoleExample, PermissionFoo)3435 // Add a guest user36 perms.SetUserRoles(user, RoleExample)3738 // Call a permissioned callback39 args := boards.Args{"bob"}40 perms.WithPermission(user, PermissionFoo, args, func() {41 println("Hello Bob!")42 })4344 // Output:45 // Hello Bob!46}47Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.