Search Apps Documentation Source Content File Folder Download Copy Actions Download

resources.gno

0.65 Kb ยท 37 lines
 1package daokit
 2
 3import (
 4	"gno.land/p/nt/avl"
 5	"gno.land/p/samcrew/daocond"
 6)
 7
 8type ResourcesStore struct {
 9	Tree *avl.Tree // string -> daocond.Condition
10}
11
12// XXX: should condition be a pointer?
13type Resource struct {
14	Handler     ActionHandler
15	Condition   daocond.Condition
16	DisplayName string
17	Description string
18}
19
20func NewResourcesStore() *ResourcesStore {
21	return &ResourcesStore{
22		Tree: avl.NewTree(),
23	}
24}
25
26func (r *ResourcesStore) Set(resource *Resource) {
27	r.Tree.Set(resource.Handler.Type(), resource)
28}
29
30func (r *ResourcesStore) Get(name string) *Resource {
31	value, ok := r.Tree.Get(name)
32	if !ok {
33		return nil
34	}
35	res := value.(*Resource)
36	return res
37}