Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

state_target.gno

1.12 Kb · 50 lines
 1package manager
 2
 3type TargetConfig struct {
 4	FunctionRoles map[Selector]RoleId
 5	Closed        bool
 6}
 7
 8func NewTargetConfig(closed bool) *TargetConfig {
 9	return &TargetConfig{
10		FunctionRoles: make(map[Selector]RoleId),
11		Closed:        closed,
12	}
13}
14
15func (targetConfig *TargetConfig) setFunctionRole(selector Selector, role RoleId) {
16	targetConfig.ensureFunctionRoles()
17
18	targetConfig.FunctionRoles[selector] = role
19}
20
21func (targetConfig *TargetConfig) setFunctionRoles(selectors []Selector, role RoleId) {
22	for i := range selectors {
23		targetConfig.setFunctionRole(selectors[i], role)
24	}
25}
26
27func (targetConfig *TargetConfig) functionRole(selector Selector) RoleId {
28	targetConfig.ensureFunctionRoles()
29
30	role, found := targetConfig.FunctionRoles[selector]
31	if !found {
32		return AdminRole
33	}
34
35	return role
36}
37
38func (targetConfig *TargetConfig) setClosed(closed bool) {
39	targetConfig.Closed = closed
40}
41
42func (targetConfig *TargetConfig) isClosed() bool {
43	return targetConfig.Closed
44}
45
46func (targetConfig *TargetConfig) ensureFunctionRoles() {
47	if targetConfig.FunctionRoles == nil {
48		targetConfig.FunctionRoles = make(map[Selector]RoleId)
49	}
50}