99 lines
2.6 KiB
Go
99 lines
2.6 KiB
Go
package attr
|
|
|
|
/*
|
|
Scope model for peer attributes and requests
|
|
|
|
A local peer "Alice" has a PublicScope that is queryable by getVal requests.
|
|
By default, for now, other scopes are private, of which we here define SettingsScope
|
|
|
|
Alice's peer structs of remote peers such as "Bob" keep the queried
|
|
PublicScope values in the PeerScope, which can be overridden by the same named
|
|
values stored in the LocalScope.
|
|
|
|
*/
|
|
|
|
// Scope strongly types Scope strings
|
|
type Scope string
|
|
|
|
// ScopedZonedPath typed path with a scope and a zone
|
|
type ScopedZonedPath string
|
|
|
|
// scopes for attributes
|
|
const (
|
|
// on a peer, local and peer supplied data
|
|
LocalScope = Scope("local")
|
|
PeerScope = Scope("peer")
|
|
ConversationScope = Scope("conversation")
|
|
|
|
// on a local profile, public data and private settings
|
|
PublicScope = Scope("public")
|
|
|
|
UnknownScope = Scope("unknown")
|
|
)
|
|
|
|
// Separator for scope and the rest of path
|
|
const Separator = "."
|
|
|
|
// IntoScope converts a string to a Scope
|
|
func IntoScope(scope string) Scope {
|
|
switch scope {
|
|
case "local":
|
|
return LocalScope
|
|
case "peer":
|
|
return PeerScope
|
|
case "conversation":
|
|
return ConversationScope
|
|
case "public":
|
|
return PublicScope
|
|
}
|
|
return UnknownScope
|
|
}
|
|
|
|
// ConstructScopedZonedPath enforces a scope over a zoned path
|
|
func (scope Scope) ConstructScopedZonedPath(zonedPath ZonedPath) ScopedZonedPath {
|
|
return ScopedZonedPath(string(scope) + Separator + string(zonedPath))
|
|
}
|
|
|
|
// ToString converts a ScopedZonedPath to a string
|
|
func (szp ScopedZonedPath) ToString() string {
|
|
return string(szp)
|
|
}
|
|
|
|
// IsLocal returns true if the scope is a local scope
|
|
func (scope Scope) IsLocal() bool {
|
|
return scope == LocalScope
|
|
}
|
|
|
|
// IsPeer returns true if the scope is a peer scope
|
|
func (scope Scope) IsPeer() bool {
|
|
return scope == PeerScope
|
|
}
|
|
|
|
// IsPublic returns true if the scope is a public scope
|
|
func (scope Scope) IsPublic() bool {
|
|
return scope == PublicScope
|
|
}
|
|
|
|
// IsConversation returns true if the scope is a conversation scope
|
|
func (scope Scope) IsConversation() bool {
|
|
return scope == ConversationScope
|
|
}
|
|
|
|
// GetLocalScope takes a path and attaches the local scope to it
|
|
// Deprecated: Use ConstructScopedZonedPath
|
|
func GetLocalScope(path string) string {
|
|
return string(LocalScope) + Separator + path
|
|
}
|
|
|
|
// GetPublicScope takes a path and attaches the local scope to it
|
|
// Deprecated: Use ConstructScopedZonedPath
|
|
func GetPublicScope(path string) string {
|
|
return string(PublicScope) + Separator + path
|
|
}
|
|
|
|
// GetPeerScope takes a path and attaches the peer scope to it
|
|
// Deprecated: Use ConstructScopedZonedPath
|
|
func GetPeerScope(path string) string {
|
|
return string(PeerScope) + Separator + path
|
|
}
|