使用默认http,加入隐藏配置enable

This commit is contained in:
dexter
2022-02-23 17:27:44 +08:00
parent de9766f917
commit 6509674d67
6 changed files with 32 additions and 29 deletions

View File

@@ -72,12 +72,11 @@ type Engine struct {
EnableAVCC bool //启用AVCC格式rtmp协议使用 EnableAVCC bool //启用AVCC格式rtmp协议使用
EnableRTP bool //启用RTP格式rtsp、gb18181等协议使用 EnableRTP bool //启用RTP格式rtsp、gb18181等协议使用
EnableFLV bool //开启FLV格式hdl协议使用 EnableFLV bool //开启FLV格式hdl协议使用
EnablePProf bool //开启pprof
} }
var Global = &Engine{ var Global = &Engine{
Publish{true, true, false, 10, 0}, Publish{true, true, false, 10, 0},
Subscribe{true, true, false, 10}, Subscribe{true, true, false, 10},
HTTP{ListenAddr: ":8080", CORS: true}, HTTP{ListenAddr: ":8080", CORS: true},
false, true, true, true, true, false, true, true, true,
} }

5
go.mod
View File

@@ -21,7 +21,4 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )
require ( require github.com/pion/randutil v0.1.0 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
github.com/pion/randutil v0.1.0 // indirect
)

2
go.sum
View File

@@ -1,6 +1,4 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY= github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY=

21
http.go
View File

@@ -3,11 +3,11 @@ package engine
import ( import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/http/pprof"
"github.com/Monibuca/engine/v4/config" "github.com/Monibuca/engine/v4/config"
"github.com/Monibuca/engine/v4/log" "github.com/Monibuca/engine/v4/log"
. "github.com/logrusorgru/aurora" . "github.com/logrusorgru/aurora"
"go.uber.org/zap"
) )
type GlobalConfig struct { type GlobalConfig struct {
@@ -18,22 +18,11 @@ type GlobalConfig struct {
func (cfg *GlobalConfig) OnEvent(event any) { func (cfg *GlobalConfig) OnEvent(event any) {
switch event.(type) { switch event.(type) {
case FirstConfig: case FirstConfig:
if cfg.EnablePProf {
cfg.HandleFunc("/debug/pprof/", pprof.Index)
cfg.HandleFunc("/debug/pprof/profile",pprof.Profile)
cfg.HandleFunc("/debug/pprof/trace", pprof.Trace)
// cfg.HandleFunc("/debug/pprof/profile", pprof.Profile)
// cfg.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
// cfg.Handle("/debug/pprof/block", pprof.Handler("block"))
// cfg.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
// cfg.Handle("/debug/pprof/heap", pprof.Handler("heap"))
// cfg.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
// cfg.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
}
log.Info(Green("api server start at"), BrightBlue(cfg.ListenAddr), BrightBlue(cfg.ListenAddrTLS)) log.Info(Green("api server start at"), BrightBlue(cfg.ListenAddr), BrightBlue(cfg.ListenAddrTLS))
// cfg.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { cfg.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// w.Write([]byte("Monibuca API Server")) log.Debug("visit", zap.String("path", "/"), zap.String("remote", r.RemoteAddr))
// }) w.Write([]byte("Monibuca API Server"))
})
go cfg.Listen(Engine, cfg) go cfg.Listen(Engine, cfg)
} }
} }

View File

@@ -22,13 +22,15 @@ import (
) )
var ( var (
ExecPath = os.Args[0]
ExecDir = filepath.Dir(ExecPath)
// ConfigRaw 配置信息的原始数据 // ConfigRaw 配置信息的原始数据
ConfigRaw []byte ConfigRaw []byte
StartTime time.Time //启动时间 StartTime time.Time //启动时间
Plugins = make(map[string]*Plugin) // Plugins 所有的插件配置 Plugins = make(map[string]*Plugin) // Plugins 所有的插件配置
EngineConfig = &GlobalConfig{ EngineConfig = &GlobalConfig{
Engine: config.Global, Engine: config.Global,
ServeMux: http.NewServeMux(), ServeMux: http.DefaultServeMux,
} }
settingDir string //配置缓存目录,该目录按照插件名称作为文件名存储修改过的配置 settingDir string //配置缓存目录,该目录按照插件名称作为文件名存储修改过的配置
Engine = InstallPlugin(EngineConfig) //复用安装插件逻辑将全局配置信息注入并启动server Engine = InstallPlugin(EngineConfig) //复用安装插件逻辑将全局配置信息注入并启动server
@@ -55,11 +57,14 @@ type PullOnSubscribe struct {
} }
func (p PullOnSubscribe) Pull() { func (p PullOnSubscribe) Pull() {
p.OnEvent(p.Puller) p.OnEvent(PullerPromise{util.NewPromise[Puller, error](p.Puller)})
} }
// Run 启动Monibuca引擎传入总的Context可用于关闭所有 // Run 启动Monibuca引擎传入总的Context可用于关闭所有
func Run(ctx context.Context, configFile string) (err error) { func Run(ctx context.Context, configFile string) (err error) {
if _, err := os.Stat(configFile); err != nil {
configFile = filepath.Join(ExecDir, configFile)
}
Engine.Context = ctx Engine.Context = ctx
if err := util.CreateShutdownScript(); err != nil { if err := util.CreateShutdownScript(); err != nil {
log.Error("create shutdown script error:", err) log.Error("create shutdown script error:", err)

View File

@@ -94,6 +94,10 @@ func (opt *Plugin) assign() {
} }
} }
} }
if opt.RawConfig["enable"] == false {
opt.Warn("disabled")
return
}
t := reflect.TypeOf(opt.Config).Elem() t := reflect.TypeOf(opt.Config).Elem()
// 用全局配置覆盖没有设置的配置 // 用全局配置覆盖没有设置的配置
for _, fname := range MergeConfigs { for _, fname := range MergeConfigs {
@@ -201,7 +205,11 @@ func (opt *Plugin) Subscribe(streamPath string, sub ISubscriber) error {
var noPullConfig = errors.New("no pull config") var noPullConfig = errors.New("no pull config")
func (opt *Plugin) Pull(streamPath string, url string) error { type PullerPromise struct {
*util.Promise[Puller, error]
}
func (opt *Plugin) Pull(streamPath string, url string, save bool) error {
conf, ok := opt.Config.(config.PullConfig) conf, ok := opt.Config.(config.PullConfig)
if !ok { if !ok {
return noPullConfig return noPullConfig
@@ -210,8 +218,15 @@ func (opt *Plugin) Pull(streamPath string, url string) error {
puller.StreamPath = streamPath puller.StreamPath = streamPath
puller.RemoteURL = url puller.RemoteURL = url
puller.Config = conf.GetPullConfig() puller.Config = conf.GetPullConfig()
promise := util.NewPromise[Puller, bool](puller) promise := util.NewPromise[Puller, error](puller)
opt.Config.OnEvent(promise) opt.Config.OnEvent(PullerPromise{promise})
_, err := promise.AWait() _, err := promise.AWait()
if err == nil && save {
puller.Config.AddPull(streamPath, url)
opt.Modified["pull"] = config.Struct2Config(puller.Config)
if err := opt.Save(); err != nil {
opt.Error("save faild", zap.Error(err))
}
}
return err return err
} }