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)
| 119 | // It returns a shallow copy of the client subscriptions matching the prefixes. |
| 120 | // If no prefix is specified, returns all subscriptions. |
| 121 | func (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 | // |
no outgoing calls