diff --git a/main.go b/main.go index faf1642..4128b88 100644 --- a/main.go +++ b/main.go @@ -74,12 +74,7 @@ func main() { return } - streamKey := settings.StreamKey - if sKey != nil && len(*sKey) != 0 { - streamKey = *sKey - } - - if urlParts[1] != streamKey { + if urlParts[1] != settings.GetStreamKey() { fmt.Println("Due to key not match, denied stream") return //If key not match, deny stream } @@ -161,7 +156,11 @@ func main() { os.Exit(1) } - fmt.Println("Stream key: ", streamKey) + if sKey != nil && len(*sKey) != 0 { + settings.SetTempKey(*sKey) + } + + fmt.Println("Stream key: ", settings.GetStreamKey()) fmt.Println("Admin password: ", settings.AdminPassword) go http.ListenAndServe(address, nil) diff --git a/settings.go b/settings.go index f5816ec..8320341 100644 --- a/settings.go +++ b/settings.go @@ -19,6 +19,7 @@ type Settings struct { Bans []BanInfo StreamKey string ListenAddress string + cmdLineKey string // stream key from the command line } type BanInfo struct { @@ -128,3 +129,20 @@ func (s *Settings) IsBanned(host string) (bool, []string) { } return false, nil } + +func (s *Settings) SetTempKey(key string) { + defer settingsMtx.Unlock() + settingsMtx.Lock() + + s.cmdLineKey = key +} + +func (s *Settings) GetStreamKey() string { + defer settingsMtx.Unlock() + settingsMtx.Lock() + + if len(s.cmdLineKey) > 0 { + return s.cmdLineKey + } + return s.StreamKey +}