Documentation
¶
Index ¶
- Constants
- func ExtractTopicIDsFromURI(ctx context.Context, uri string, existingTopicIDs []string, ...) []string
- func UpdateTopicCache(ctx context.Context, serviceAuthToken string, topicClient topicCli.Clienter) func() *Topic
- type Subtopic
- type Subtopics
- type Topic
- type TopicCache
- func (tc *TopicCache) AddUpdateFunc(title string, updateFunc func() *Topic)
- func (tc *TopicCache) GetData(ctx context.Context, key string) (*Topic, error)
- func (tc *TopicCache) GetTopic(ctx context.Context, slug string) (*Subtopic, error)
- func (tc *TopicCache) GetTopicCacheKey() string
- func (tc *TopicCache) IsMockCache(ctx context.Context) bool
Constants ¶
const (
// TopicCacheKey is used to cache the topics
TopicCacheKey = "root-topic-cache"
)
Variables ¶
This section is empty.
Functions ¶
func ExtractTopicIDsFromURI ¶
func ExtractTopicIDsFromURI(ctx context.Context, uri string, existingTopicIDs []string, topicCache *TopicCache) []string
ExtractTopicIDsFromURI extracts topic IDs from a URI by matching URI segments to topics in the cache. It breaks the URI into segments, matches them against the topic cache, and returns a deduplicated list of topic IDs. Existing topic IDs can be provided and will be preserved in the result.
func UpdateTopicCache ¶
func UpdateTopicCache(ctx context.Context, serviceAuthToken string, topicClient topicCli.Clienter) func() *Topic
UpdateTopicCache is a function to update the topic cache in publishing (private) mode. This function talks to the dp-topic-api via its private endpoints to retrieve the root topic and its subtopic ids. The data returned by the dp-topic-api is of type *models.PrivateSubtopics which is then transformed in this function for the controller. If an error has occurred, this is captured in log.Error and then an empty topic is returned
Types ¶
type Subtopic ¶
type Subtopic struct {
ID string
LocaliseKeyName string
Slug string
ReleaseDate *time.Time
// This is a reference to the parent topic
ParentID string
ParentSlug string
}
Subtopic represents the data which is cached for a subtopic to be used by the dis-migration-service
type Subtopics ¶
type Subtopics struct {
// contains filtered or unexported fields
}
Subtopics contains a list of subtopics in map form with mutex locking. The subtopicsMap is used to keep a record of subtopics to be later used to generate the subtopics id query for a topic and to check if the subtopic id given by a user exists
func NewSubTopicsMap ¶
func NewSubTopicsMap() *Subtopics
NewSubTopicsMap creates a new subtopics id map to store subtopic ids with mutex locking
func (*Subtopics) AppendSubtopicID ¶
AppendSubtopicID appends the subtopic to the map stored in Subtopics with consideration to mutex locking
func (*Subtopics) GetSubtopics ¶
GetSubtopics returns an array of subtopics
type Topic ¶
type Topic struct {
ID string
LocaliseKeyName string
Slug string
ReleaseDate *time.Time
// List is a map of subtopics containing the topic slug and subtopic details
List *Subtopics
}
Topic represents the data which is cached for a topic to be used by the dis-migration-service
func GetEmptyTopic ¶
func GetEmptyTopic() *Topic
GetEmptyTopic returns an empty topic cache e.g in an event where updating the cache of the topic fails
type TopicCache ¶
TopicCache is a wrapper to dpcache.Cache which has additional fields and methods specifically for caching topics
func NewMockTopicCache ¶
func NewMockTopicCache(ctx context.Context) (*TopicCache, error)
NewMockTopicCache creates a topic cache with a single mock topic for when the topic cache feature is disabled
func NewPopulatedTopicCacheForTest ¶
func NewPopulatedTopicCacheForTest(ctx context.Context) (*TopicCache, error)
NewPopulatedTopicCacheForTest creates a topic cache with basic test data. This ensures tests never use an empty cache, which would be invalid in production.
func NewTopicCache ¶
NewTopicCache creates a topic cache object to be used in the service which will update at every updateInterval. If updateInterval is nil, this means that the cache will only be updated once at the start of the service
func (*TopicCache) AddUpdateFunc ¶
func (tc *TopicCache) AddUpdateFunc(title string, updateFunc func() *Topic)
AddUpdateFunc adds an update function to the topic cache for a topic with the title passed to the function. This update function will then be triggered once or at every fixed interval as per the prior setup of the TopicCache
func (*TopicCache) GetData ¶
GetData returns the topic cache requested by key and returns an empty topic if not found, not of the cache interface type or nil.
func (*TopicCache) GetTopicCacheKey ¶
func (tc *TopicCache) GetTopicCacheKey() string
GetTopicCacheKey gets the constant value set for the root topic cache key
func (*TopicCache) IsMockCache ¶
func (tc *TopicCache) IsMockCache(ctx context.Context) bool
IsMockCache checks if this is a mock topic cache by looking for the mock-topic