File size: 415 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package permission

import (
	"context"
	"fmt"
)

func ExampleUserContext() {
	// start with any context
	ctx := context.Background()

	// pass it through UserContext to assign a user ID and Role
	ctx = UserContext(ctx, "user-id-here", RoleAdmin)

	// later on it can be checked anywhere; this example will satisfy the Admin role requirement
	err := LimitCheckAny(ctx, Admin)

	fmt.Println(err)
	// output: <nil>
}