Add general info API
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -37,6 +38,7 @@ func Init() {
|
|||||||
initStatic(cfg.Mod.StaticDir)
|
initStatic(cfg.Mod.StaticDir)
|
||||||
initWS(cfg.Mod.Origin)
|
initWS(cfg.Mod.Origin)
|
||||||
|
|
||||||
|
HandleFunc("api", apiHandler)
|
||||||
HandleFunc("api/config", configHandler)
|
HandleFunc("api/config", configHandler)
|
||||||
HandleFunc("api/exit", exitHandler)
|
HandleFunc("api/exit", exitHandler)
|
||||||
HandleFunc("api/streams", streamsHandler)
|
HandleFunc("api/streams", streamsHandler)
|
||||||
@@ -100,6 +102,18 @@ func middlewareCORS(next http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
|
func apiHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
mu.Lock()
|
||||||
|
app.Info["host"] = r.Host
|
||||||
|
mu.Unlock()
|
||||||
|
|
||||||
|
if err := json.NewEncoder(w).Encode(app.Info); err != nil {
|
||||||
|
log.Warn().Err(err).Caller().Send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func exitHandler(w http.ResponseWriter, r *http.Request) {
|
func exitHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "", http.StatusBadRequest)
|
http.Error(w, "", http.StatusBadRequest)
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ var Version = "0.1-rc.8"
|
|||||||
var UserAgent = "go2rtc/" + Version
|
var UserAgent = "go2rtc/" + Version
|
||||||
|
|
||||||
var ConfigPath string
|
var ConfigPath string
|
||||||
|
var Info = map[string]interface{}{
|
||||||
|
"version": Version,
|
||||||
|
}
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
flag.StringVar(
|
flag.StringVar(
|
||||||
@@ -24,6 +27,8 @@ func Init() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
Info["config_path"] = ConfigPath
|
||||||
|
|
||||||
data, _ = os.ReadFile(ConfigPath)
|
data, _ = os.ReadFile(ConfigPath)
|
||||||
|
|
||||||
var cfg struct {
|
var cfg struct {
|
||||||
|
|||||||
+4
-3
@@ -14,9 +14,9 @@ import (
|
|||||||
func Init() {
|
func Init() {
|
||||||
var conf struct {
|
var conf struct {
|
||||||
Mod struct {
|
Mod struct {
|
||||||
Listen string `yaml:"listen"`
|
Listen string `yaml:"listen" json:"listen"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username" json:"-"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password" json:"-"`
|
||||||
} `yaml:"rtsp"`
|
} `yaml:"rtsp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ func Init() {
|
|||||||
conf.Mod.Listen = ":8554"
|
conf.Mod.Listen = ":8554"
|
||||||
|
|
||||||
app.LoadConfig(&conf)
|
app.LoadConfig(&conf)
|
||||||
|
app.Info["rtsp"] = conf.Mod
|
||||||
|
|
||||||
log = app.GetLogger("rtsp")
|
log = app.GetLogger("rtsp")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user