mirror of
https://github.com/Monibuca/engine.git
synced 2025-11-03 10:51:03 +08:00
使用默认http,加入隐藏配置enable
This commit is contained in:
@@ -72,12 +72,11 @@ type Engine struct {
|
||||
EnableAVCC bool //启用AVCC格式,rtmp协议使用
|
||||
EnableRTP bool //启用RTP格式,rtsp、gb18181等协议使用
|
||||
EnableFLV bool //开启FLV格式,hdl协议使用
|
||||
EnablePProf bool //开启pprof
|
||||
}
|
||||
|
||||
var Global = &Engine{
|
||||
Publish{true, true, false, 10, 0},
|
||||
Subscribe{true, true, false, 10},
|
||||
HTTP{ListenAddr: ":8080", CORS: true},
|
||||
false, true, true, true, true,
|
||||
false, true, true, true,
|
||||
}
|
||||
|
||||
5
go.mod
5
go.mod
@@ -21,7 +21,4 @@ require (
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
|
||||
github.com/pion/randutil v0.1.0 // indirect
|
||||
)
|
||||
require github.com/pion/randutil v0.1.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,6 +1,4 @@
|
||||
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/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY=
|
||||
|
||||
21
http.go
21
http.go
@@ -3,11 +3,11 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/Monibuca/engine/v4/config"
|
||||
"github.com/Monibuca/engine/v4/log"
|
||||
. "github.com/logrusorgru/aurora"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type GlobalConfig struct {
|
||||
@@ -18,22 +18,11 @@ type GlobalConfig struct {
|
||||
func (cfg *GlobalConfig) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
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))
|
||||
// cfg.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
|
||||
// w.Write([]byte("Monibuca API Server"))
|
||||
// })
|
||||
cfg.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("visit", zap.String("path", "/"), zap.String("remote", r.RemoteAddr))
|
||||
w.Write([]byte("Monibuca API Server"))
|
||||
})
|
||||
go cfg.Listen(Engine, cfg)
|
||||
}
|
||||
}
|
||||
|
||||
9
main.go
9
main.go
@@ -22,13 +22,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ExecPath = os.Args[0]
|
||||
ExecDir = filepath.Dir(ExecPath)
|
||||
// ConfigRaw 配置信息的原始数据
|
||||
ConfigRaw []byte
|
||||
StartTime time.Time //启动时间
|
||||
Plugins = make(map[string]*Plugin) // Plugins 所有的插件配置
|
||||
EngineConfig = &GlobalConfig{
|
||||
Engine: config.Global,
|
||||
ServeMux: http.NewServeMux(),
|
||||
ServeMux: http.DefaultServeMux,
|
||||
}
|
||||
settingDir string //配置缓存目录,该目录按照插件名称作为文件名存储修改过的配置
|
||||
Engine = InstallPlugin(EngineConfig) //复用安装插件逻辑,将全局配置信息注入,并启动server
|
||||
@@ -55,11 +57,14 @@ type PullOnSubscribe struct {
|
||||
}
|
||||
|
||||
func (p PullOnSubscribe) Pull() {
|
||||
p.OnEvent(p.Puller)
|
||||
p.OnEvent(PullerPromise{util.NewPromise[Puller, error](p.Puller)})
|
||||
}
|
||||
|
||||
// Run 启动Monibuca引擎,传入总的Context,可用于关闭所有
|
||||
func Run(ctx context.Context, configFile string) (err error) {
|
||||
if _, err := os.Stat(configFile); err != nil {
|
||||
configFile = filepath.Join(ExecDir, configFile)
|
||||
}
|
||||
Engine.Context = ctx
|
||||
if err := util.CreateShutdownScript(); err != nil {
|
||||
log.Error("create shutdown script error:", err)
|
||||
|
||||
21
plugin.go
21
plugin.go
@@ -94,6 +94,10 @@ func (opt *Plugin) assign() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if opt.RawConfig["enable"] == false {
|
||||
opt.Warn("disabled")
|
||||
return
|
||||
}
|
||||
t := reflect.TypeOf(opt.Config).Elem()
|
||||
// 用全局配置覆盖没有设置的配置
|
||||
for _, fname := range MergeConfigs {
|
||||
@@ -201,7 +205,11 @@ func (opt *Plugin) Subscribe(streamPath string, sub ISubscriber) error {
|
||||
|
||||
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)
|
||||
if !ok {
|
||||
return noPullConfig
|
||||
@@ -210,8 +218,15 @@ func (opt *Plugin) Pull(streamPath string, url string) error {
|
||||
puller.StreamPath = streamPath
|
||||
puller.RemoteURL = url
|
||||
puller.Config = conf.GetPullConfig()
|
||||
promise := util.NewPromise[Puller, bool](puller)
|
||||
opt.Config.OnEvent(promise)
|
||||
promise := util.NewPromise[Puller, error](puller)
|
||||
opt.Config.OnEvent(PullerPromise{promise})
|
||||
_, 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user