Skip to content

Commit 15ec995

Browse files
committed
Add config for the list of modules to init
1 parent 231cab3 commit 15ec995

File tree

2 files changed

+72
-60
lines changed

2 files changed

+72
-60
lines changed

internal/app/app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
var (
1313
Version string
14+
Modules []string
1415
UserAgent string
1516
ConfigPath string
1617
Info = make(map[string]any)
@@ -76,6 +77,16 @@ func Init() {
7677
if ConfigPath != "" {
7778
Logger.Info().Str("path", ConfigPath).Msg("config")
7879
}
80+
81+
var cfg struct {
82+
Mod struct {
83+
Modules []string `yaml:"modules"`
84+
} `yaml:"app"`
85+
}
86+
87+
LoadConfig(&cfg)
88+
89+
Modules = cfg.Mod.Modules
7990
}
8091

8192
func readRevisionTime() (revision, vcsTime string) {

main.go

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"slices"
5+
46
"github.com/AlexxIT/go2rtc/internal/alsa"
57
"github.com/AlexxIT/go2rtc/internal/api"
68
"github.com/AlexxIT/go2rtc/internal/api/ws"
@@ -46,66 +48,65 @@ import (
4648
func main() {
4749
app.Version = "1.9.11"
4850

49-
// 1. Core modules: app, api/ws, streams
50-
51-
app.Init() // init config and logs
52-
53-
api.Init() // init API before all others
54-
ws.Init() // init WS API endpoint
55-
56-
streams.Init() // streams module
57-
58-
// 2. Main sources and servers
59-
60-
rtsp.Init() // rtsp source, RTSP server
61-
webrtc.Init() // webrtc source, WebRTC server
62-
63-
// 3. Main API
64-
65-
mp4.Init() // MP4 API
66-
hls.Init() // HLS API
67-
mjpeg.Init() // MJPEG API
68-
69-
// 4. Other sources and servers
70-
71-
hass.Init() // hass source, Hass API server
72-
onvif.Init() // onvif source, ONVIF API server
73-
webtorrent.Init() // webtorrent source, WebTorrent module
74-
wyoming.Init()
75-
76-
// 5. Other sources
77-
78-
rtmp.Init() // rtmp source
79-
exec.Init() // exec source
80-
ffmpeg.Init() // ffmpeg source
81-
echo.Init() // echo source
82-
ivideon.Init() // ivideon source
83-
http.Init() // http/tcp source
84-
dvrip.Init() // dvrip source
85-
tapo.Init() // tapo source
86-
isapi.Init() // isapi source
87-
mpegts.Init() // mpegts passive source
88-
roborock.Init() // roborock source
89-
homekit.Init() // homekit source
90-
ring.Init() // ring source
91-
nest.Init() // nest source
92-
bubble.Init() // bubble source
93-
expr.Init() // expr source
94-
gopro.Init() // gopro source
95-
doorbird.Init() // doorbird source
96-
v4l2.Init() // v4l2 source
97-
alsa.Init() // alsa source
98-
flussonic.Init()
99-
eseecloud.Init()
100-
yandex.Init()
101-
102-
// 6. Helper modules
103-
104-
ngrok.Init() // ngrok module
105-
srtp.Init() // SRTP server
106-
debug.Init() // debug API
107-
108-
// 7. Go
51+
type module struct {
52+
name string
53+
init func()
54+
}
55+
56+
modules := []module{
57+
{"", app.Init}, // init config and logs
58+
{"api", api.Init}, // init API before all others
59+
{"ws", ws.Init}, // init WS API endpoint
60+
{"", streams.Init},
61+
// Main sources and servers
62+
{"http", http.Init}, // rtsp source, HTTP server
63+
{"rtsp", rtsp.Init}, // rtsp source, RTSP server
64+
{"webrtc", webrtc.Init}, // webrtc source, WebRTC server
65+
// Main API
66+
{"mp4", mp4.Init}, // MP4 API
67+
{"hls", hls.Init}, // HLS API
68+
{"mjpeg", mjpeg.Init}, // MJPEG API
69+
// Other sources and servers
70+
{"hass", hass.Init}, // hass source, Hass API server
71+
{"homekit", homekit.Init}, // homekit source, HomeKit server
72+
{"onvif", onvif.Init}, // onvif source, ONVIF API server
73+
{"rtmp", rtmp.Init}, // rtmp source, RTMP server
74+
{"webtorrent", webtorrent.Init}, // webtorrent source, WebTorrent module
75+
{"wyoming", wyoming.Init},
76+
// Exec and script sources
77+
{"echo", echo.Init},
78+
{"exec", exec.Init},
79+
{"expr", expr.Init},
80+
{"ffmpeg", ffmpeg.Init},
81+
// Hardware sources
82+
{"alsa", alsa.Init},
83+
{"v4l2", v4l2.Init},
84+
// Other sources
85+
{"bubble", bubble.Init},
86+
{"doorbird", doorbird.Init},
87+
{"dvrip", dvrip.Init},
88+
{"eseecloud", eseecloud.Init},
89+
{"flussonic", flussonic.Init},
90+
{"gopro", gopro.Init},
91+
{"isapi", isapi.Init},
92+
{"ivideon", ivideon.Init},
93+
{"mpegts", mpegts.Init},
94+
{"nest", nest.Init},
95+
{"ring", ring.Init},
96+
{"roborock", roborock.Init},
97+
{"tapo", tapo.Init},
98+
{"yandex", yandex.Init},
99+
// Helper modules
100+
{"debug", debug.Init},
101+
{"ngrok", ngrok.Init},
102+
{"srtp", srtp.Init},
103+
}
104+
105+
for _, m := range modules {
106+
if app.Modules == nil || m.name == "" || slices.Contains(app.Modules, m.name) {
107+
m.init()
108+
}
109+
}
109110

110111
shell.RunUntilSignal()
111112
}

0 commit comments

Comments
 (0)