加入summary 优化http监听逻辑,实现基本身份认证

This commit is contained in:
dexter
2022-03-01 20:42:25 +08:00
parent 37586d4a0b
commit abe2cdd1fc
11 changed files with 326 additions and 64 deletions

22
http.go
View File

@@ -3,28 +3,22 @@ package engine
import (
"encoding/json"
"net/http"
"time"
. "github.com/logrusorgru/aurora"
"go.uber.org/zap"
"m7s.live/engine/v4/config"
"m7s.live/engine/v4/log"
"m7s.live/engine/v4/util"
)
type GlobalConfig struct {
*http.ServeMux
*config.Engine
}
func (cfg *GlobalConfig) OnEvent(event any) {
switch event.(type) {
case FirstConfig:
log.Info(Green("api server start at"), BrightBlue(cfg.ListenAddr), BrightBlue(cfg.ListenAddrTLS))
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)
}
func (config *GlobalConfig) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("Monibuca API Server"))
}
func (config *GlobalConfig) API_summary(rw http.ResponseWriter, r *http.Request) {
util.ReturnJson(summary.collect, time.Second, rw, r)
}
func (config *GlobalConfig) API_sysInfo(rw http.ResponseWriter, r *http.Request) {