// NewStateMachine return a pointer of new StateMachine func NewStateMachine(states ...string) *StateMachine { stateE := make([]gset.Elementer, len(states)) for i, state := range states { stateE[i] = gset.T(state) } stateSet := gset.NewSet(stateE...) return &StateMachine{make(map[string]*Event), stateSet} }
// Allow add perssion set into a role func (r *Role) Allow(resourcer Resourcer, permissions ...Permission) *Role { permissionsE := make([]gset.IdGetter, len(permissions)) for i, permission := range permissions { permissionsE[i] = permission } permissionSet, ok := r.allowPermissions[resourcer.TableName()] if ok { permissionSet.Add(permissionsE...) } else { r.allowPermissions[resourcer.TableName()] = gset.NewSet(permissionsE...) } return r }