(streamPath string, url string, puller IPuller, save int)
| 266 | var Pullers sync.Map |
| 267 | |
| 268 | func (opt *Plugin) Pull(streamPath string, url string, puller IPuller, save int) (err error) { |
| 269 | conf, ok := opt.Config.(config.PullConfig) |
| 270 | if !ok { |
| 271 | return ErrNoPullConfig |
| 272 | } |
| 273 | pullConf := conf.GetPullConfig() |
| 274 | if save < 2 { |
| 275 | zurl := zap.String("url", url) |
| 276 | zpath := zap.String("stream", streamPath) |
| 277 | opt.Info("pull", zpath, zurl) |
| 278 | puller.init(streamPath, url, pullConf) |
| 279 | opt.AssignPubConfig(puller.GetPublisher()) |
| 280 | puller.SetLogger(opt.Logger.With(zpath, zurl)) |
| 281 | go puller.startPull(puller) |
| 282 | } |
| 283 | switch save { |
| 284 | case 1: |
| 285 | pullConf.PullOnStartLocker.Lock() |
| 286 | defer pullConf.PullOnStartLocker.Unlock() |
| 287 | m := map[string]string{streamPath: url} |
| 288 | for id := range pullConf.PullOnStart { |
| 289 | m[id] = pullConf.PullOnStart[id] |
| 290 | } |
| 291 | m[streamPath] = url |
| 292 | opt.RawConfig.ParseModifyFile(map[string]any{ |
| 293 | "pull": map[string]any{ |
| 294 | "pullonstart": m, |
| 295 | }, |
| 296 | }) |
| 297 | case 2: |
| 298 | pullConf.PullOnSubLocker.Lock() |
| 299 | defer pullConf.PullOnSubLocker.Unlock() |
| 300 | m := map[string]string{streamPath: url} |
| 301 | for id := range pullConf.PullOnSub { |
| 302 | m[id] = pullConf.PullOnSub[id] |
| 303 | } |
| 304 | m[streamPath] = url |
| 305 | if pullConf.PullOnSub == nil { |
| 306 | pullConf.PullOnSub = make(map[string]string) |
| 307 | } |
| 308 | pullConf.PullOnSub[streamPath] = url |
| 309 | opt.RawConfig.ParseModifyFile(map[string]any{ |
| 310 | "pull": map[string]any{ |
| 311 | "pullonsub": m, |
| 312 | }, |
| 313 | }) |
| 314 | } |
| 315 | if save > 0 { |
| 316 | if err = opt.Save(); err != nil { |
| 317 | opt.Error("save faild", zap.Error(err)) |
| 318 | } |
| 319 | } |
| 320 | return |
| 321 | } |
| 322 | |
| 323 | var ErrNoPushConfig = errors.New("no push config") |
| 324 | var Pushers sync.Map |
nothing calls this directly
no test coverage detected