新增:频道(topic)细粒度权限控制,是否允许订阅消息、是否允许发送消息到频道

This commit is contained in:
2023-07-16 01:33:25 +08:00
parent 66772cb659
commit bf82800afc
8 changed files with 412 additions and 55 deletions

View File

@@ -0,0 +1,41 @@
package auth
import (
"fmt"
"log"
"regexp"
"testing"
)
func TestAuth(t *testing.T) {
// Create an instance of PermissionManager
p := &PermissionManager{}
// Initialize the permission manager
err := p.Init()
if err != nil {
log.Fatal(err)
}
// Example usage: Get permissions by token
token := "token-12345"
userId, err := p.GetUserIdByToken(token)
if err != nil {
log.Fatal(err)
}
fmt.Println("Permissions:")
check := p.AuthCheck(userId, "zcore:abx", "r")
check2 := p.AuthCheck(userId, "zcore:abx", "r")
fmt.Println("check:", check)
fmt.Println("check2:", check2)
}
func TestName(t *testing.T) {
exp := "zcore:*"
channel := "zcore:axxx"
compile, _ := regexp.Compile(exp)
//matched, _ := regexp.MatchString(exp, channel)
matched := compile.MatchString(channel)
fmt.Println("matched:", matched)
}