From 664a6dc198c5ac833754b02b7e76bd53abba958d Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 4 Apr 2022 15:58:48 -0700 Subject: [PATCH] attr/parseScope() --- model/attr/scope.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/model/attr/scope.go b/model/attr/scope.go index 8c9d67d..406d1a9 100644 --- a/model/attr/scope.go +++ b/model/attr/scope.go @@ -1,5 +1,10 @@ package attr +import ( + "git.openprivacy.ca/openprivacy/log" + "strings" +) + /* Scope model for peer attributes and requests @@ -78,3 +83,16 @@ func (scope Scope) IsPublic() bool { func (scope Scope) IsConversation() bool { return scope == ConversationScope } + +// ParseScope takes in an untyped string and returns an explicit Scope along with the rest of the untyped path +func ParseScope(path string) (Scope, string) { + parts := strings.SplitN(path, Separator, 3) + + log.Debugf("parsed scope: %v %v", parts, path) + + if len(parts) != 3 { + return UnknownScope, "" + } + + return IntoScope(parts[0]), parts[1] + Separator + parts[2] +}