优化从API实现代码中提取角色的方法

This commit is contained in:
刘祥超
2022-10-25 16:32:16 +08:00
parent 9a38d40937
commit 18765d29f2
2 changed files with 3748 additions and 3815 deletions

View File

@@ -160,7 +160,19 @@ func main() {
roles = append(roles, "admin")
}
if strings.Contains(methodSource, ".ValidateAdminAndUser(") {
roles = append(roles, "admin", "user")
var hasRoles = false
var wordIndex = strings.Index(methodSource, ".ValidateAdminAndUser(")
if wordIndex > 0 {
if len(methodSource[wordIndex:]) > 100 {
if strings.Contains(methodSource[wordIndex:wordIndex+100], ".ValidateAdminAndUser(ctx, false)") {
roles = append(roles, "admin")
hasRoles = true
}
}
if !hasRoles {
roles = append(roles, "admin", "user")
}
}
}
if strings.Contains(methodSource, ".ValidateNSNode(") {
roles = append(roles, "dns")