diff --git a/cmd/api/config.go b/cmd/api/config.go index 137ab883..1bc257cb 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -63,13 +63,13 @@ func mergeYAML(file1 string, yaml2 []byte) ([]byte, error) { } // Unmarshal the first YAML file into a map - var config1 map[string]interface{} + var config1 map[string]any if err = yaml.Unmarshal(data1, &config1); err != nil { return nil, err } // Unmarshal the second YAML document into a map - var config2 map[string]interface{} + var config2 map[string]any if err = yaml.Unmarshal(yaml2, &config2); err != nil { return nil, err } @@ -81,15 +81,15 @@ func mergeYAML(file1 string, yaml2 []byte) ([]byte, error) { return yaml.Marshal(&config1) } -func merge(dst, src map[string]interface{}) map[string]interface{} { +func merge(dst, src map[string]any) map[string]any { for k, v := range src { if vv, ok := dst[k]; ok { switch vv := vv.(type) { - case map[string]interface{}: - v := v.(map[string]interface{}) + case map[string]any: + v := v.(map[string]any) dst[k] = merge(vv, v) - case []interface{}: - v := v.([]interface{}) + case []any: + v := v.([]any) dst[k] = v default: dst[k] = v diff --git a/cmd/api/ws.go b/cmd/api/ws.go index f7a49900..90585736 100644 --- a/cmd/api/ws.go +++ b/cmd/api/ws.go @@ -84,7 +84,7 @@ func apiWS(w http.ResponseWriter, r *http.Request) { } tr := &Transport{Request: r} - tr.OnWrite(func(msg interface{}) { + tr.OnWrite(func(msg any) { _ = ws.SetWriteDeadline(time.Now().Add(time.Second * 5)) if data, ok := msg.([]byte); ok { @@ -130,11 +130,11 @@ type Transport struct { wrmx sync.Mutex onChange func() - onWrite func(msg interface{}) + onWrite func(msg any) onClose []func() } -func (t *Transport) OnWrite(f func(msg interface{})) { +func (t *Transport) OnWrite(f func(msg any)) { t.mx.Lock() if t.onChange != nil { t.onChange() @@ -143,7 +143,7 @@ func (t *Transport) OnWrite(f func(msg interface{})) { t.mx.Unlock() } -func (t *Transport) Write(msg interface{}) { +func (t *Transport) Write(msg any) { t.wrmx.Lock() t.onWrite(msg) t.wrmx.Unlock() diff --git a/cmd/app/app.go b/cmd/app/app.go index 40d85dd3..e24eb7e7 100644 --- a/cmd/app/app.go +++ b/cmd/app/app.go @@ -18,7 +18,7 @@ var Version = "1.2.0" var UserAgent = "go2rtc/" + Version var ConfigPath string -var Info = map[string]interface{}{ +var Info = map[string]any{ "version": Version, } @@ -94,7 +94,7 @@ func NewLogger(format string, level string) zerolog.Logger { return zerolog.New(writer).With().Timestamp().Logger().Level(lvl) } -func LoadConfig(v interface{}) { +func LoadConfig(v any) { for _, data := range configs { if err := yaml.Unmarshal(data, v); err != nil { log.Warn().Err(err).Msg("[app] read config") diff --git a/cmd/app/store/store.go b/cmd/app/store/store.go index e18d1714..d18de624 100644 --- a/cmd/app/store/store.go +++ b/cmd/app/store/store.go @@ -8,7 +8,7 @@ import ( const name = "go2rtc.json" -var store map[string]interface{} +var store map[string]any func load() { data, _ := os.ReadFile(name) @@ -20,7 +20,7 @@ func load() { } if store == nil { - store = make(map[string]interface{}) + store = make(map[string]any) } } @@ -33,7 +33,7 @@ func save() error { return os.WriteFile(name, data, 0644) } -func GetRaw(key string) interface{} { +func GetRaw(key string) any { if store == nil { load() } @@ -41,16 +41,16 @@ func GetRaw(key string) interface{} { return store[key] } -func GetDict(key string) map[string]interface{} { +func GetDict(key string) map[string]any { raw := GetRaw(key) if raw != nil { - return raw.(map[string]interface{}) + return raw.(map[string]any) } - return make(map[string]interface{}) + return make(map[string]any) } -func Set(key string, v interface{}) error { +func Set(key string, v any) error { if store == nil { load() } diff --git a/cmd/hls/hls.go b/cmd/hls/hls.go index 18031e29..98f2cb94 100644 --- a/cmd/hls/hls.go +++ b/cmd/hls/hls.go @@ -83,7 +83,7 @@ func handlerStream(w http.ResponseWriter, r *http.Request) { session := &Session{cons: cons} - cons.Listen(func(msg interface{}) { + cons.(any).(*core.Listener).Listen(func(msg any) { if data, ok := msg.([]byte); ok { session.mu.Lock() session.segment = append(session.segment, data...) diff --git a/cmd/homekit/api.go b/cmd/homekit/api.go index 53279b1a..a055871a 100644 --- a/cmd/homekit/api.go +++ b/cmd/homekit/api.go @@ -15,7 +15,7 @@ import ( func apiHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": - items := make([]interface{}, 0) + items := make([]any, 0) for name, src := range store.GetDict("streams") { if src := src.(string); strings.HasPrefix(src, "homekit") { diff --git a/cmd/mjpeg/mjpeg.go b/cmd/mjpeg/mjpeg.go index f116ad70..ffb1caed 100644 --- a/cmd/mjpeg/mjpeg.go +++ b/cmd/mjpeg/mjpeg.go @@ -32,7 +32,7 @@ func handlerKeyframe(w http.ResponseWriter, r *http.Request) { RemoteAddr: r.RemoteAddr, UserAgent: r.UserAgent(), } - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { switch msg := msg.(type) { case []byte: exit <- msg @@ -84,7 +84,7 @@ func outputMjpeg(w http.ResponseWriter, r *http.Request) { RemoteAddr: r.RemoteAddr, UserAgent: r.UserAgent(), } - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { switch msg := msg.(type) { case []byte: data := []byte(header + strconv.Itoa(len(msg))) @@ -149,7 +149,7 @@ func handlerWS(tr *api.Transport, _ *api.Message) error { RemoteAddr: tr.Request.RemoteAddr, UserAgent: tr.Request.UserAgent(), } - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { if data, ok := msg.([]byte); ok { tr.Write(data) } diff --git a/cmd/mp4/mp4.go b/cmd/mp4/mp4.go index d98cae80..ee3a1c89 100644 --- a/cmd/mp4/mp4.go +++ b/cmd/mp4/mp4.go @@ -46,7 +46,7 @@ func handlerKeyframe(w http.ResponseWriter, r *http.Request) { exit := make(chan []byte) cons := &mp4.Segment{OnlyKeyframe: true} - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { if data, ok := msg.([]byte); ok && exit != nil { exit <- data exit = nil diff --git a/cmd/mp4/ws.go b/cmd/mp4/ws.go index b42e8bc1..afb6b8a3 100644 --- a/cmd/mp4/ws.go +++ b/cmd/mp4/ws.go @@ -26,7 +26,7 @@ func handlerWSMSE(tr *api.Transport, msg *api.Message) error { cons.Medias = parseMedias(codecs, true) } - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { if data, ok := msg.([]byte); ok { tr.Write(data) } @@ -74,7 +74,7 @@ func handlerWSMP4(tr *api.Transport, msg *api.Message) error { cons.Medias = parseMedias(codecs, false) } - cons.Listen(func(msg interface{}) { + cons.Listen(func(msg any) { if data, ok := msg.([]byte); ok { tr.Write(data) } diff --git a/cmd/ngrok/ngrok.go b/cmd/ngrok/ngrok.go index 6df2d54c..25266b08 100644 --- a/cmd/ngrok/ngrok.go +++ b/cmd/ngrok/ngrok.go @@ -30,7 +30,7 @@ func Init() { log.Error().Err(err).Msg("[ngrok] start") } - ngr.Listen(func(msg interface{}) { + ngr.Listen(func(msg any) { if msg := msg.(*ngrok.Message); msg != nil { if strings.HasPrefix(msg.Line, "ERROR:") { log.Warn().Msg("[ngrok] " + msg.Line) diff --git a/cmd/rtsp/rtsp.go b/cmd/rtsp/rtsp.go index ce9a723b..86041677 100644 --- a/cmd/rtsp/rtsp.go +++ b/cmd/rtsp/rtsp.go @@ -106,7 +106,7 @@ func rtspHandler(url string) (streamer.Producer, error) { conn.UserAgent = app.UserAgent if log.Trace().Enabled() { - conn.Listen(func(msg interface{}) { + conn.Listen(func(msg any) { switch msg := msg.(type) { case *tcp.Request: log.Trace().Msgf("[rtsp] client request:\n%s", msg) @@ -147,7 +147,7 @@ func tcpHandler(conn *rtsp.Conn) { trace := log.Trace().Enabled() - conn.Listen(func(msg interface{}) { + conn.Listen(func(msg any) { if trace { switch msg := msg.(type) { case *tcp.Request: diff --git a/cmd/streams/stream.go b/cmd/streams/stream.go index cc707819..f6da32b8 100644 --- a/cmd/streams/stream.go +++ b/cmd/streams/stream.go @@ -24,7 +24,7 @@ func NewStream(source interface{}) *Stream { prod := &Producer{url: source} s.producers = append(s.producers, prod) return s - case []interface{}: + case []any: s := new(Stream) for _, source := range source { prod := &Producer{url: source.(string)} @@ -33,7 +33,7 @@ func NewStream(source interface{}) *Stream { return s case *Stream: return source - case map[string]interface{}: + case map[string]any: return NewStream(source["url"]) case nil: return new(Stream) diff --git a/cmd/streams/streams.go b/cmd/streams/streams.go index f2ab97ee..8c5a454a 100644 --- a/cmd/streams/streams.go +++ b/cmd/streams/streams.go @@ -11,7 +11,7 @@ import ( func Init() { var cfg struct { - Mod map[string]interface{} `yaml:"streams"` + Mod map[string]any `yaml:"streams"` } app.LoadConfig(&cfg) @@ -33,7 +33,7 @@ func Get(name string) *Stream { return streams[name] } -func New(name string, source interface{}) *Stream { +func New(name string, source any) *Stream { stream := NewStream(source) streams[name] = stream return stream diff --git a/cmd/webrtc/server.go b/cmd/webrtc/server.go index 2f189a8b..10e9394f 100644 --- a/cmd/webrtc/server.go +++ b/cmd/webrtc/server.go @@ -185,7 +185,7 @@ func inputWebRTC(w http.ResponseWriter, r *http.Request) { id := strconv.FormatInt(time.Now().UnixNano(), 36) sessions[id] = prod - prod.Listen(func(msg interface{}) { + prod.Listen(func(msg any) { switch msg := msg.(type) { case pion.PeerConnectionState: if msg == pion.PeerConnectionStateClosed { diff --git a/cmd/webtorrent/init.go b/cmd/webtorrent/init.go index 7a484fa9..f8b905a8 100644 --- a/cmd/webtorrent/init.go +++ b/cmd/webtorrent/init.go @@ -52,7 +52,7 @@ func Init() { } if log.Debug().Enabled() { - srv.Listen(func(msg interface{}) { + srv.Listen(func(msg any) { switch msg.(type) { case string, error: log.Debug().Msgf("[webtorrent] %s", msg) diff --git a/pkg/dvrip/client.go b/pkg/dvrip/client.go index 9b8f6251..abcd5ddb 100644 --- a/pkg/dvrip/client.go +++ b/pkg/dvrip/client.go @@ -38,7 +38,7 @@ type Client struct { audioSeq uint16 } -type Response map[string]interface{} +type Response map[string]any const Login = uint16(1000) const OPMonitorClaim = uint16(1413) diff --git a/pkg/hap/character.go b/pkg/hap/character.go index 051fd046..a19eb7a8 100644 --- a/pkg/hap/character.go +++ b/pkg/hap/character.go @@ -91,7 +91,7 @@ func (c *Character) GenerateEvent() (data []byte, err error) { } // Set new value and NotifyListeners -func (c *Character) Set(v interface{}) (err error) { +func (c *Character) Set(v any) (err error) { if err = c.Write(v); err != nil { return } @@ -99,7 +99,7 @@ func (c *Character) Set(v interface{}) (err error) { } // Write new value with right format -func (c *Character) Write(v interface{}) (err error) { +func (c *Character) Write(v any) (err error) { switch c.Format { case characteristic.FormatTLV8: var data []byte @@ -120,7 +120,7 @@ func (c *Character) Write(v interface{}) (err error) { } // ReadTLV8 value to right struct -func (c *Character) ReadTLV8(v interface{}) (err error) { +func (c *Character) ReadTLV8(v any) (err error) { var data []byte if data, err = base64.StdEncoding.DecodeString(c.Value.(string)); err != nil { return diff --git a/pkg/hap/conn.go b/pkg/hap/conn.go index f0607dd6..0b51c6d9 100644 --- a/pkg/hap/conn.go +++ b/pkg/hap/conn.go @@ -35,7 +35,7 @@ type Conn struct { ClientPrivate []byte OnEvent func(res *http.Response) - Output func(msg interface{}) + Output func(msg any) conn net.Conn secure *Secure diff --git a/pkg/hap/helpers.go b/pkg/hap/helpers.go index 95abf403..46e4c7ad 100644 --- a/pkg/hap/helpers.go +++ b/pkg/hap/helpers.go @@ -38,7 +38,7 @@ type PairVerifyPayload struct { Signature []byte `tlv8:"10,optional"` } -//func (c *Character) Unmarshal(value interface{}) error { +//func (c *Character) Unmarshal(value any) error { // switch c.Format { // case characteristic.FormatTLV8: // data, err := base64.StdEncoding.DecodeString(c.Value.(string)) @@ -50,7 +50,7 @@ type PairVerifyPayload struct { // return nil //} -//func (c *Character) Marshal(value interface{}) error { +//func (c *Character) Marshal(value any) error { // switch c.Format { // case characteristic.FormatTLV8: // data, err := tlv8.Marshal(value) diff --git a/pkg/httpflv/amf0.go b/pkg/httpflv/amf0.go index b84b0add..82a2e72f 100644 --- a/pkg/httpflv/amf0.go +++ b/pkg/httpflv/amf0.go @@ -27,7 +27,7 @@ func NewReader(b []byte) *AMF0 { return &AMF0{buf: b} } -func (a *AMF0) ReadMetaData() map[string]interface{} { +func (a *AMF0) ReadMetaData() map[string]any { if b, _ := a.ReadByte(); b != TypeString { return nil } @@ -48,8 +48,8 @@ func (a *AMF0) ReadMetaData() map[string]interface{} { return nil } -func (a *AMF0) ReadMap() (map[interface{}]interface{}, error) { - dict := make(map[interface{}]interface{}) +func (a *AMF0) ReadMap() (map[any]any, error) { + dict := make(map[any]any) for a.pos < len(a.buf) { k, err := a.ReadItem() @@ -66,7 +66,7 @@ func (a *AMF0) ReadMap() (map[interface{}]interface{}, error) { return dict, nil } -func (a *AMF0) ReadItem() (interface{}, error) { +func (a *AMF0) ReadItem() (any, error) { dataType, err := a.ReadByte() if err != nil { return nil, err @@ -131,8 +131,8 @@ func (a *AMF0) ReadString() (string, error) { return s, nil } -func (a *AMF0) ReadObject() (map[string]interface{}, error) { - obj := make(map[string]interface{}) +func (a *AMF0) ReadObject() (map[string]any, error) { + obj := make(map[string]any) for { k, err := a.ReadString() @@ -155,7 +155,7 @@ func (a *AMF0) ReadObject() (map[string]interface{}, error) { return obj, nil } -func (a *AMF0) ReadEcmaArray() (map[string]interface{}, error) { +func (a *AMF0) ReadEcmaArray() (map[string]any, error) { if a.pos+4 >= len(a.buf) { return nil, Err } diff --git a/pkg/httpflv/httpflv.go b/pkg/httpflv/httpflv.go index 523401d8..ba13f500 100644 --- a/pkg/httpflv/httpflv.go +++ b/pkg/httpflv/httpflv.go @@ -176,7 +176,7 @@ func (c *Conn) Close() (err error) { return c.conn.Close() } -func parseAudioConfig(meta map[string]interface{}) av.CodecData { +func parseAudioConfig(meta map[string]any) av.CodecData { if meta["audiocodecid"] != float64(10) { return nil } diff --git a/pkg/ngrok/ngrok.go b/pkg/ngrok/ngrok.go index b26453ef..82773de7 100644 --- a/pkg/ngrok/ngrok.go +++ b/pkg/ngrok/ngrok.go @@ -24,7 +24,7 @@ type Message struct { Line string } -func NewNgrok(command interface{}) (*Ngrok, error) { +func NewNgrok(command any) (*Ngrok, error) { var arg []string switch command.(type) { case string: diff --git a/pkg/tcp/textproto_test.go b/pkg/tcp/textproto_test.go index a8981c4c..08bc5a1e 100644 --- a/pkg/tcp/textproto_test.go +++ b/pkg/tcp/textproto_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func assert(t *testing.T, one, two interface{}) { +func assert(t *testing.T, one, two any) { if one != two { t.FailNow() }