mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-07 01:22:51 +08:00
更新json序列化忽略字段
This commit is contained in:
11
http.go
11
http.go
@@ -32,12 +32,11 @@ func (conf *GlobalConfig) API_closeStream(w http.ResponseWriter, r *http.Request
|
||||
if streamPath := r.URL.Query().Get("streamPath"); streamPath != "" {
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Close()
|
||||
w.Write([]byte("success"))
|
||||
} else {
|
||||
w.Write([]byte("no such stream"))
|
||||
http.Error(w, "no such stream", http.StatusNotFound)
|
||||
}
|
||||
} else {
|
||||
w.Write([]byte("no query stream"))
|
||||
http.Error(w, "no streamPath", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ func (conf *GlobalConfig) API_getConfig(w http.ResponseWriter, r *http.Request)
|
||||
if c, ok := Plugins[configName]; ok {
|
||||
json.NewEncoder(w).Encode(c.RawConfig)
|
||||
} else {
|
||||
w.Write([]byte("no such config"))
|
||||
http.Error(w, "no such config", http.StatusNotFound)
|
||||
}
|
||||
} else {
|
||||
json.NewEncoder(w).Encode(Engine.RawConfig)
|
||||
@@ -62,7 +61,7 @@ func (conf *GlobalConfig) API_modifyConfig(w http.ResponseWriter, r *http.Reques
|
||||
c.Save()
|
||||
c.RawConfig.Assign(c.Modified)
|
||||
} else {
|
||||
w.Write([]byte("no such config"))
|
||||
http.Error(w, "no such config", http.StatusNotFound)
|
||||
}
|
||||
} else {
|
||||
json.NewDecoder(r.Body).Decode(&Engine.Modified)
|
||||
@@ -77,7 +76,7 @@ func (conf *GlobalConfig) API_updateConfig(w http.ResponseWriter, r *http.Reques
|
||||
if c, ok := Plugins[configName]; ok {
|
||||
c.Update(c.Modified)
|
||||
} else {
|
||||
w.Write([]byte("no such config"))
|
||||
http.Error(w, "no such config", http.StatusNotFound)
|
||||
}
|
||||
} else {
|
||||
Engine.Update(Engine.Modified)
|
||||
|
6
io.go
6
io.go
@@ -26,15 +26,15 @@ type IO[C IOConfig, S IIO] struct {
|
||||
Type string
|
||||
context.Context `json:"-"` //不要直接设置,应当通过OnEvent传入父级Context
|
||||
context.CancelFunc `json:"-"` //流关闭是关闭发布者或者订阅者
|
||||
*zap.Logger
|
||||
*zap.Logger `json:"-"`
|
||||
StartTime time.Time //创建时间
|
||||
Stream *Stream `json:"-"`
|
||||
io.Reader `json:"-"`
|
||||
io.Writer `json:"-"`
|
||||
io.Closer `json:"-"`
|
||||
Args url.Values
|
||||
Config *C
|
||||
Spesic S
|
||||
Config *C `json:"-"`
|
||||
Spesic S `json:"-"`
|
||||
}
|
||||
|
||||
func (io *IO[C, S]) IsClosed() bool {
|
||||
|
1
main.go
1
main.go
@@ -66,6 +66,7 @@ func Run(ctx context.Context, configFile string) (err error) {
|
||||
Engine.registerHandler()
|
||||
// 使得RawConfig具备全量配置信息,用于合并到插件配置中
|
||||
Engine.RawConfig = config.Struct2Config(EngineConfig.Engine)
|
||||
log.With(zap.String("config", "global")).Debug("", zap.Any("config", EngineConfig))
|
||||
go EngineConfig.Listen(Engine)
|
||||
for name, plugin := range Plugins {
|
||||
plugin.RawConfig = cg.GetChild(name)
|
||||
|
@@ -16,9 +16,10 @@ type IPublisher interface {
|
||||
|
||||
type Publisher struct {
|
||||
IO[config.Publish, IPublisher]
|
||||
common.AudioTrack
|
||||
common.VideoTrack
|
||||
common.AudioTrack `json:"-"`
|
||||
common.VideoTrack `json:"-"`
|
||||
}
|
||||
|
||||
func (p *Publisher) Stop() {
|
||||
p.IO.Stop()
|
||||
p.Stream.Receive(ACTION_PUBLISHLOST)
|
||||
|
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -78,7 +79,11 @@ type PlayContext[T interface {
|
||||
Track T
|
||||
ring *AVRing[R]
|
||||
confSeq int
|
||||
First AVFrame[R]
|
||||
First AVFrame[R] `json:"-"`
|
||||
}
|
||||
|
||||
func (p *PlayContext[T, R]) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(p.Track)
|
||||
}
|
||||
|
||||
func (p *PlayContext[T, R]) init(t T) {
|
||||
@@ -99,7 +104,7 @@ type TrackPlayer struct {
|
||||
// Subscriber 订阅者实体定义
|
||||
type Subscriber struct {
|
||||
IO[config.Subscribe, ISubscriber]
|
||||
TrackPlayer
|
||||
TrackPlayer `json:"-"`
|
||||
}
|
||||
|
||||
func (s *Subscriber) OnEvent(event any) {
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
func ReturnJson[T any](fetch func() T, tickDur time.Duration, rw http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Query().Get("json") != "" {
|
||||
if err := json.NewEncoder(rw).Encode(fetch()); err != nil {
|
||||
rw.WriteHeader(500)
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user