Documentation ¶
Overview ¶
Package topics provides some helpers for managing topics in memory.
Index ¶
- Variables
- func NameHash(name string) string
- type NameGroup
- func (g *NameGroup) Add(name string, id ulid.ULID) error
- func (g *NameGroup) AddTopic(topic *api.Topic) (err error)
- func (g *NameGroup) Contains(s string) bool
- func (g *NameGroup) ContainsTopicHash(hash []byte) bool
- func (g *NameGroup) ContainsTopicID(topicID ulid.ULID) bool
- func (g *NameGroup) ContainsTopicName(name string) bool
- func (g *NameGroup) Filter(topics ...string) *NameGroup
- func (g *NameGroup) FilterTopicID(topicIDs ...ulid.ULID) *NameGroup
- func (g *NameGroup) FilterTopicName(names ...string) *NameGroup
- func (g *NameGroup) Length() int
- func (g *NameGroup) Lookup(s string) (name string, topicID ulid.ULID, ok bool)
- func (g *NameGroup) LookupTopicHash(hash []byte) (string, ulid.ULID, bool)
- func (g *NameGroup) LookupTopicID(topicID ulid.ULID) (string, bool)
- func (g *NameGroup) LookupTopicName(name string) (ulid.ULID, bool)
- func (g *NameGroup) TopicIDs() []ulid.ULID
- func (g *NameGroup) TopicMap() map[string][]byte
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyExists = errors.New("topic name or ID already exists in group") ErrEmptyReference = errors.New("topic name and ID cannot be empty") )
Functions ¶
Types ¶
type NameGroup ¶
type NameGroup struct {
// contains filtered or unexported fields
}
A topics group is a set of related topics (e.g. topics that belong to the same project) that allow easy lookups between topic names and IDs for easy referencing. TODO: should name groups also handle name hashes?
func (*NameGroup) Add ¶
Add a topic reference to the names group consisting of the topic name and ID.
func (*NameGroup) Contains ¶
Contains checks if the string is contained by the name group. It first checks to see if the string is a valid topic name, and if so it checks the names hash; then it checks if the string is a parseable ulid, and if so it checks the ID field. Finally, it checks if the string is a base64 encoded topic hash, and checks the name hashes.
func (*NameGroup) ContainsTopicHash ¶
Check if the name group contains the specified topic hash.
func (*NameGroup) ContainsTopicID ¶
Check if the name group contains the specified topicID
func (*NameGroup) ContainsTopicName ¶
Check if the name group contains the specified topic name
func (*NameGroup) Filter ¶ added in v0.9.0
Filter the topics name group by topic names, IDs, or base64 encoded hashes. This is the primary way to filter a topic name group from the user. The returned name group is a subset of the topics that are both in the original name group and specified by the list of topics. The original NameGroup is not modified.
func (*NameGroup) FilterTopicID ¶
Filter the topics name group by the specified topicIDs, returning the subset of topics that are both in the original named group and specified by the list of IDs. E.g. if the topicID is in the original name group it is kept, otherwise it is omitted. A new NameGroup is returned, the original is not modified.
func (*NameGroup) FilterTopicName ¶
Filter the topics name group by the specified topic names, returning the subset of topics that are both in the original named group and specified by the list of names. E.g. if the name is in the original name group it is kept, otherwise it is omitted. A new NameGroup is returned, the original is not modified.
func (*NameGroup) Lookup ¶ added in v0.9.0
Lookup checks if the string is contained in the name group with similar semantics to Contains. If found, it will return the name and topicID, otherwise empty values.
func (*NameGroup) LookupTopicHash ¶ added in v0.9.0
Lookup the name and topicID for the specified topic name hash.
func (*NameGroup) LookupTopicID ¶ added in v0.9.0
Lookup the name of a topic by its ID
func (*NameGroup) LookupTopicName ¶ added in v0.9.0
Lookup the ID of a topic by its name