(appName string, streamName string, shouldCreate bool)
| 147 | } |
| 148 | |
| 149 | func (gm *ComplexGroupManager) getGroup(appName string, streamName string, shouldCreate bool) (group *Group, createFlag bool) { |
| 150 | var ok bool |
| 151 | if appName == "" { |
| 152 | group, ok = gm.onlyStreamNameGroups[streamName] |
| 153 | if ok { |
| 154 | return group, false |
| 155 | } |
| 156 | // 虽然没有appName,也有可能在appNameStreamNameGroups中,我们遍历查找 |
| 157 | // |
| 158 | // 注意,此时有可能不同appName的容器里都有对应这个streamName的group,但是程序已没法区分,系统使用者应规范流名称避免出现这种问题 |
| 159 | // |
| 160 | for _, m := range gm.appNameStreamNameGroups { |
| 161 | group, ok = m[streamName] |
| 162 | if ok { |
| 163 | return group, false |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // 两个容器都没找到 |
| 168 | if shouldCreate { |
| 169 | group = gm.groupCreator.CreateGroup(appName, streamName) |
| 170 | gm.onlyStreamNameGroups[streamName] = group |
| 171 | return group, true |
| 172 | } else { |
| 173 | return nil, false |
| 174 | } |
| 175 | } else { // appName存在 |
| 176 | // 先在对应appName中查找 |
| 177 | m, mok := gm.appNameStreamNameGroups[appName] |
| 178 | if mok { |
| 179 | group, ok = m[streamName] |
| 180 | if ok { |
| 181 | return group, false |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // 虽然有appName,也有可能在onlyStreamNameGroups中,我们尝试一下 |
| 186 | group, ok = gm.onlyStreamNameGroups[streamName] |
| 187 | if ok { |
| 188 | return group, false |
| 189 | } |
| 190 | |
| 191 | // 都没有找到 |
| 192 | if shouldCreate { |
| 193 | group = gm.groupCreator.CreateGroup(appName, streamName) |
| 194 | if !mok { |
| 195 | m = make(map[string]*Group) |
| 196 | gm.appNameStreamNameGroups[appName] = m |
| 197 | } |
| 198 | m[streamName] = group |
| 199 | return group, true |
| 200 | } else { |
| 201 | return nil, false |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | func (gm *ComplexGroupManager) Iterate(onIterateGroup func(group *Group) bool) { |
no test coverage detected