(node string, source LogSource, pattern string, isRegex bool)
| 113 | } |
| 114 | |
| 115 | func (m *LogManager) Subscribe(node string, source LogSource, pattern string, isRegex bool) (*LogSubscription, error) { |
| 116 | m.mu.Lock() |
| 117 | defer m.mu.Unlock() |
| 118 | |
| 119 | key := sourceKey{node, source} |
| 120 | if _, ok := m.subscribers[key]; ok { |
| 121 | return nil, fmt.Errorf("node %s source %s already has a subscriber", node, source) |
| 122 | } |
| 123 | |
| 124 | sub := &LogSubscription{ |
| 125 | Node: node, |
| 126 | Source: source, |
| 127 | MatchCh: make(chan struct{}, 1), |
| 128 | } |
| 129 | if isRegex { |
| 130 | re, err := regexp.Compile(pattern) |
| 131 | if err != nil { |
| 132 | return nil, err |
| 133 | } |
| 134 | sub.Regex = re |
| 135 | } else { |
| 136 | sub.Pattern = pattern |
| 137 | } |
| 138 | |
| 139 | m.subscribers[key] = sub |
| 140 | m.checkMatchLocked(key) |
| 141 | |
| 142 | return sub, nil |
| 143 | } |
| 144 | |
| 145 | func (m *LogManager) Unsubscribe(sub *LogSubscription) { |
| 146 | m.mu.Lock() |
no test coverage detected