From e0fb371fd9d44a1600c87486b43211b0e5e735c5 Mon Sep 17 00:00:00 2001 From: dexter <178529795@qq.com> Date: Sun, 4 Sep 2022 11:53:45 +0800 Subject: [PATCH] =?UTF-8?q?HDL=E6=8F=92=E4=BB=B6=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 16 +++++++++------- pull.go | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index f3a8f7a..1481f3a 100644 --- a/main.go +++ b/main.go @@ -28,8 +28,8 @@ func (c *HDLConfig) OnEvent(event any) { case FirstConfig: if c.PullOnStart { for streamPath, url := range c.PullList { - if err := plugin.Pull(streamPath, url, new(HDLPuller), false); err != nil { - plugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err)) + if err := HDLPlugin.Pull(streamPath, url, new(HDLPuller), false); err != nil { + HDLPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err)) } } } @@ -37,8 +37,8 @@ func (c *HDLConfig) OnEvent(event any) { if c.PullOnSubscribe { for streamPath, url := range c.PullList { if streamPath == v.Path { - if err := plugin.Pull(streamPath, url, new(HDLPuller), false); err != nil { - plugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err)) + if err := HDLPlugin.Pull(streamPath, url, new(HDLPuller), false); err != nil { + HDLPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err)) } break } @@ -48,9 +48,11 @@ func (c *HDLConfig) OnEvent(event any) { } func (c *HDLConfig) API_Pull(rw http.ResponseWriter, r *http.Request) { - err := plugin.Pull(r.URL.Query().Get("streamPath"), r.URL.Query().Get("target"), new(HDLPuller), r.URL.Query().Has("save")) + err := HDLPlugin.Pull(r.URL.Query().Get("streamPath"), r.URL.Query().Get("target"), new(HDLPuller), r.URL.Query().Has("save")) if err != nil { http.Error(rw, err.Error(), http.StatusBadRequest) + } else { + rw.Write([]byte("ok")) } } @@ -60,7 +62,7 @@ func (*HDLConfig) API_List(rw http.ResponseWriter, r *http.Request) { // 确保HDLConfig实现了PullPlugin接口 -var plugin = InstallPlugin(new(HDLConfig)) +var HDLPlugin = InstallPlugin(new(HDLConfig)) type HDLSubscriber struct { Subscriber @@ -124,7 +126,7 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) { sub.ID = r.RemoteAddr sub.SetParentCtx(r.Context()) sub.SetIO(w) - if err := plugin.SubscribeBlock(streamPath, sub, SUBTYPE_FLV); err != nil { + if err := HDLPlugin.SubscribeBlock(streamPath, sub, SUBTYPE_FLV); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) } } diff --git a/pull.go b/pull.go index aebc437..eccc207 100644 --- a/pull.go +++ b/pull.go @@ -14,7 +14,7 @@ import ( ) func (puller *HDLPuller) Connect() (err error) { - plugin.Info("connect", zap.String("remoteURL", puller.RemoteURL)) + HDLPlugin.Info("connect", zap.String("remoteURL", puller.RemoteURL)) if strings.HasPrefix(puller.RemoteURL, "http") { var res *http.Response if res, err = http.Get(puller.RemoteURL); err == nil { @@ -72,4 +72,4 @@ type HDLPuller struct { Publisher Puller absTS uint32 //绝对时间戳 -} \ No newline at end of file +}