Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: refactor the code, rename Lock to NIOLock and fix typos #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ https://casbin.org/docs/tutorials

```swift
import Casbin
let e = try Enforer("examples/rbac_model.conf", "examples/rbac_policy.csv")
let e = try Enforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
```

3. Besides the static policy file, Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Sources/Casbin/Cache/MemoryCache.swift
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ final class LruCache<Key:Hashable,Value> {
}
private var storage:[Key:ListNode] = [:]
var capacity = 0
private var lock:Lock
private var lock: NIOLock

/// head's nextNode is the actual first node in the Double Linked-list.
private var head = ListNode()
10 changes: 5 additions & 5 deletions Sources/Casbin/Core/Core.swift
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ extension Enforcer {
self.core.storage.locks
}

public var sync: Lock {
public var sync: NIOLock {
self.locks.main
}

@@ -86,23 +86,23 @@ extension Enforcer {
}

public final class Locks {
public let main: Lock
var storage: [ObjectIdentifier: Lock]
public let main: NIOLock
var storage: [ObjectIdentifier: NIOLock]

init() {
self.main = .init()
self.storage = [:]
}

public func lock<Key>(for key: Key.Type) -> Lock
public func lock<Key>(for key: Key.Type) -> NIOLock
where Key: LockKey
{
self.main.lock()
defer { self.main.unlock() }
if let existing = self.storage[ObjectIdentifier(Key.self)] {
return existing
} else {
let new = Lock()
let new = NIOLock()
self.storage[ObjectIdentifier(Key.self)] = new
return new
}
4 changes: 2 additions & 2 deletions Sources/Casbin/Enforcer.swift
Original file line number Diff line number Diff line change
@@ -292,7 +292,7 @@ extension Enforcer {
return .success((eftStream.next(), eftStream.explain()))

} catch {
return .failure(error )
return .failure(error)
}

}
@@ -404,7 +404,7 @@ extension Enforcer: CoreApi {
do {
try self.buildRoleLinks().get()
} catch {
return .failure(error as! CasbinError)
return .failure(error)
}
}
return registerGFunctions()
Loading