Browse Source

fix crash when using environment variables and config file is missing (#103)

pull/169/head
aler9 5 years ago
parent
commit
57877df875
  1. 5
      confenv/confenv.go
  2. 20
      main_test.go

5
confenv/confenv.go vendored

@ -81,6 +81,11 @@ func process(env map[string]string, envKey string, rv reflect.Value) error { @@ -81,6 +81,11 @@ func process(env map[string]string, envKey string, rv reflect.Value) error {
}
mapKey = strings.ToLower(mapKey)
// initialize only if there's at least one key
if rv.IsNil() {
rv.Set(reflect.MakeMap(rt))
}
nv := rv.MapIndex(reflect.ValueOf(mapKey))
zero := reflect.Value{}
if nv == zero {

20
main_test.go

@ -202,6 +202,26 @@ func TestEnvironment(t *testing.T) { @@ -202,6 +202,26 @@ func TestEnvironment(t *testing.T) {
}, pa)
}
func TestEnvironmentNoFile(t *testing.T) {
os.Setenv("RTSP_PATHS_CAM1_SOURCE", "rtsp://testing")
defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCE")
p, err := testProgram("{}")
require.NoError(t, err)
defer p.close()
pa, ok := p.conf.Paths["cam1"]
require.Equal(t, true, ok)
require.Equal(t, &conf.PathConf{
Source: "rtsp://testing",
SourceUrl: func() *url.URL {
u, _ := url.Parse("rtsp://testing:554")
return u
}(),
SourceProtocol: "udp",
}, pa)
}
func TestPublish(t *testing.T) {
for _, conf := range []struct {
publishSoft string

Loading…
Cancel
Save