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