MCPcopy
hub / github.com/pocketbase/pocketbase / Subscriptions

Method Subscriptions

tools/subscriptions/client.go:121–149  ·  view source on GitHub ↗

Subscriptions implements the [Client.Subscriptions] interface method. It returns a shallow copy of the client subscriptions matching the prefixes. If no prefix is specified, returns all subscriptions.

(prefixes ...string)

Source from the content-addressed store, hash-verified

119// It returns a shallow copy of the client subscriptions matching the prefixes.
120// If no prefix is specified, returns all subscriptions.
121func (c *DefaultClient) Subscriptions(prefixes ...string) map[string]SubscriptionOptions {
122 c.mu.RLock()
123 defer c.mu.RUnlock()
124
125 // no prefix -> return copy of all subscriptions
126 if len(prefixes) == 0 {
127 result := make(map[string]SubscriptionOptions, len(c.subscriptions))
128
129 for s, options := range c.subscriptions {
130 result[s] = options
131 }
132
133 return result
134 }
135
136 result := make(map[string]SubscriptionOptions)
137
138 for _, prefix := range prefixes {
139 for s, options := range c.subscriptions {
140 // "?" ensures that the options query start character is always there
141 // so that it can be used as an end separator when looking only for the main subscription topic
142 if strings.HasPrefix(s+"?", prefix) {
143 result[s] = options
144 }
145 }
146 }
147
148 return result
149}
150
151// Subscribe implements the [Client.Subscribe] interface method.
152//

Callers 6

TestNewDefaultClientFunction · 0.95
TestSubscriptionsFunction · 0.95
TestSubscribeFunction · 0.95
TestSubscribeOptionsFunction · 0.95
TestUnsubscribeFunction · 0.95
TestRealtimeSubscribeFunction · 0.95

Calls

no outgoing calls

Tested by 6

TestNewDefaultClientFunction · 0.76
TestSubscriptionsFunction · 0.76
TestSubscribeFunction · 0.76
TestSubscribeOptionsFunction · 0.76
TestUnsubscribeFunction · 0.76
TestRealtimeSubscribeFunction · 0.76