topics

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package topics provides some helpers for managing topics in memory.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists  = errors.New("topic name or ID already exists in group")
	ErrEmptyReference = errors.New("topic name and ID cannot be empty")
)

Functions

func NameHash added in v0.9.0

func NameHash(name string) string

Returns a base64 encoded string of the topic name hash.

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

func (g *NameGroup) Add(name string, id ulid.ULID) error

Add a topic reference to the names group consisting of the topic name and ID.

func (*NameGroup) AddTopic

func (g *NameGroup) AddTopic(topic *api.Topic) (err error)

Add a topic reference from the topic api struct.

func (*NameGroup) Contains

func (g *NameGroup) Contains(s string) bool

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

func (g *NameGroup) ContainsTopicHash(hash []byte) bool

Check if the name group contains the specified topic hash.

func (*NameGroup) ContainsTopicID

func (g *NameGroup) ContainsTopicID(topicID ulid.ULID) bool

Check if the name group contains the specified topicID

func (*NameGroup) ContainsTopicName

func (g *NameGroup) ContainsTopicName(name string) bool

Check if the name group contains the specified topic name

func (*NameGroup) Filter added in v0.9.0

func (g *NameGroup) Filter(topics ...string) *NameGroup

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

func (g *NameGroup) FilterTopicID(topicIDs ...ulid.ULID) *NameGroup

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

func (g *NameGroup) FilterTopicName(names ...string) *NameGroup

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) Length

func (g *NameGroup) Length() int

Returns the number of items in the name group.

func (*NameGroup) Lookup added in v0.9.0

func (g *NameGroup) Lookup(s string) (name string, topicID ulid.ULID, ok bool)

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

func (g *NameGroup) LookupTopicHash(hash []byte) (string, ulid.ULID, bool)

Lookup the name and topicID for the specified topic name hash.

func (*NameGroup) LookupTopicID added in v0.9.0

func (g *NameGroup) LookupTopicID(topicID ulid.ULID) (string, bool)

Lookup the name of a topic by its ID

func (*NameGroup) LookupTopicName added in v0.9.0

func (g *NameGroup) LookupTopicName(name string) (ulid.ULID, bool)

Lookup the ID of a topic by its name

func (*NameGroup) TopicIDs added in v0.9.0

func (g *NameGroup) TopicIDs() []ulid.ULID

TopicIDs returns a slice of all of the topic ULIDs in the map.

func (*NameGroup) TopicMap

func (g *NameGroup) TopicMap() map[string][]byte

TopicMap returns a map of topic name to topic ID bytes, which is used in StreamReady messages from the server, and also to easily perform lookups in leveldb indices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL