Example #1
0
func (e *engine) GetRole(roleName string, create bool) (int, int, bool) {
	if id, ok := e.roleMap[roleName]; ok {
		return id, e.storage[id].sType, true
	} else if !create {
		return -1, -1, false
	} else {
		e.Lock()
		defer e.Unlock()
		nid := e.nextSerial()
		e.roleMap[roleName] = nid
		e.storage[nid] = &storlet{ROLE, roleName, ""}
		return nid, ROLE, false
	}
}
Example #2
0
func (e *engine) GetPerm(permName, resString string, create bool) (id int, exist bool) {
	if id, ok := e.permMap[permName][resString]; ok {
		return id, true
	} else if !create {
		return -1, false
	} else {
		e.Lock()
		defer e.Unlock()
		id := e.nextSerial()
		if _, ok := e.permMap[permName]; !ok {
			e.permMap[permName] = make(map[string]int)
		}
		e.permMap[permName][resString] = id
		e.storage[id] = &storlet{PERM, permName, resString}
		return id, false
	}
}