diff --git a/controllers/admin/logs.go b/controllers/admin/logs.go index bd16051bc..9c75fdffb 100644 --- a/controllers/admin/logs.go +++ b/controllers/admin/logs.go @@ -20,8 +20,7 @@ func GetLogs(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(response) - if err != nil { + if err := json.NewEncoder(w).Encode(response); err != nil { log.Errorln(err) } } @@ -39,8 +38,7 @@ func GetWarnings(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(response) - if err != nil { + if err := json.NewEncoder(w).Encode(response); err != nil { log.Errorln(err) } } diff --git a/controllers/admin/serverConfig.go b/controllers/admin/serverConfig.go index 91cfe02a8..b7f95a304 100644 --- a/controllers/admin/serverConfig.go +++ b/controllers/admin/serverConfig.go @@ -65,8 +65,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(response) - if err != nil { + if err := json.NewEncoder(w).Encode(response); err != nil { log.Errorln(err) } } diff --git a/controllers/chat.go b/controllers/chat.go index 0b604e737..bba843a00 100644 --- a/controllers/chat.go +++ b/controllers/chat.go @@ -18,8 +18,7 @@ func GetChatMessages(w http.ResponseWriter, r *http.Request) { case http.MethodGet: messages := core.GetAllChatMessages() - err := json.NewEncoder(w).Encode(messages) - if err != nil { + if err := json.NewEncoder(w).Encode(messages); err != nil { log.Errorln(err) } default: diff --git a/controllers/index.go b/controllers/index.go index 46f682d78..58658bd1b 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -112,9 +112,7 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "text/html") - err = tmpl.Execute(w, metadata) - - if err != nil { + if err := tmpl.Execute(w, metadata); err != nil { log.Panicln(err) } } diff --git a/controllers/status.go b/controllers/status.go index 95c58654f..70d48c243 100644 --- a/controllers/status.go +++ b/controllers/status.go @@ -15,12 +15,12 @@ func GetStatus(w http.ResponseWriter, r *http.Request) { status := core.GetStatus() response := webStatusResponse{ - Online: status.Online, - ViewerCount: status.ViewerCount, - LastConnectTime: status.LastConnectTime, + Online: status.Online, + ViewerCount: status.ViewerCount, + LastConnectTime: status.LastConnectTime, LastDisconnectTime: status.LastDisconnectTime, - VersionNumber: status.VersionNumber, - StreamTitle: status.StreamTitle, + VersionNumber: status.VersionNumber, + StreamTitle: status.StreamTitle, } w.Header().Set("Content-Type", "application/json") @@ -30,12 +30,12 @@ func GetStatus(w http.ResponseWriter, r *http.Request) { } type webStatusResponse struct { - Online bool `json:"online"` - ViewerCount int `json:"viewerCount"` + Online bool `json:"online"` + ViewerCount int `json:"viewerCount"` LastConnectTime utils.NullTime `json:"lastConnectTime"` LastDisconnectTime utils.NullTime `json:"lastDisconnectTime"` VersionNumber string `json:"versionNumber"` StreamTitle string `json:"streamTitle"` -} \ No newline at end of file +} diff --git a/core/chat/client.go b/core/chat/client.go index 8f06ee6c0..bb9275ab4 100644 --- a/core/chat/client.go +++ b/core/chat/client.go @@ -92,24 +92,20 @@ func (c *Client) listenWrite() { select { // Send a PING keepalive case msg := <-c.pingch: - err := websocket.JSON.Send(c.ws, msg) - if err != nil { + if err := websocket.JSON.Send(c.ws, msg); err != nil { c.handleClientSocketError(err) } // send message to the client case msg := <-c.ch: - err := websocket.JSON.Send(c.ws, msg) - if err != nil { + if err := websocket.JSON.Send(c.ws, msg); err != nil { c.handleClientSocketError(err) } case msg := <-c.usernameChangeChannel: - err := websocket.JSON.Send(c.ws, msg) - if err != nil { + if err := websocket.JSON.Send(c.ws, msg); err != nil { c.handleClientSocketError(err) } case msg := <-c.userJoinedChannel: - err := websocket.JSON.Send(c.ws, msg) - if err != nil { + if err := websocket.JSON.Send(c.ws, msg); err != nil { c.handleClientSocketError(err) } @@ -148,8 +144,7 @@ func (c *Client) listenRead() { // read data from websocket connection default: var data []byte - err := websocket.Message.Receive(c.ws, &data) - if err != nil { + if err := websocket.Message.Receive(c.ws, &data); err != nil { if err == io.EOF { c.doneCh <- true return @@ -162,10 +157,9 @@ func (c *Client) listenRead() { } var messageTypeCheck map[string]interface{} - err = json.Unmarshal(data, &messageTypeCheck) // Bad messages should be thrown away - if err != nil { + if err := json.Unmarshal(data, &messageTypeCheck); err != nil { log.Debugln("Badly formatted message received from", c.Username, c.ws.Request().RemoteAddr) continue } @@ -207,8 +201,7 @@ func (c *Client) userJoined(data []byte) { func (c *Client) userChangedName(data []byte) { var msg models.NameChangeEvent - err := json.Unmarshal(data, &msg) - if err != nil { + if err := json.Unmarshal(data, &msg); err != nil { log.Errorln(err) } msg.Type = models.UserNameChanged @@ -219,8 +212,7 @@ func (c *Client) userChangedName(data []byte) { func (c *Client) chatMessageReceived(data []byte) { var msg models.ChatEvent - err := json.Unmarshal(data, &msg) - if err != nil { + if err := json.Unmarshal(data, &msg); err != nil { log.Errorln(err) } diff --git a/core/chat/persistence.go b/core/chat/persistence.go index 98c3df30f..c25bc118e 100644 --- a/core/chat/persistence.go +++ b/core/chat/persistence.go @@ -33,8 +33,7 @@ func createTable() { log.Fatal(err) } defer stmt.Close() - _, err = stmt.Exec() - if err != nil { + if _, err := stmt.Exec(); err != nil { log.Warnln(err) } } @@ -51,12 +50,10 @@ func addMessage(message models.ChatEvent) { } defer stmt.Close() - _, err = stmt.Exec(message.ID, message.Author, message.Body, message.MessageType, 1, message.Timestamp) - if err != nil { + if _, err := stmt.Exec(message.ID, message.Author, message.Body, message.MessageType, 1, message.Timestamp); err != nil { log.Fatal(err) } - err = tx.Commit() - if err != nil { + if err := tx.Commit(); err != nil { log.Fatal(err) } } @@ -133,13 +130,12 @@ func saveMessageVisibility(messageIDs []string, visible bool) error { args[i+1] = id } - _, err = stmt.Exec(args...) - if err != nil { + if _, err := stmt.Exec(args...); err != nil { log.Fatal(err) return err } - if err = tx.Commit(); err != nil { + if err := tx.Commit(); err != nil { log.Fatal(err) return err } diff --git a/core/data/accessTokens.go b/core/data/accessTokens.go index 237252b8a..77a8bff56 100644 --- a/core/data/accessTokens.go +++ b/core/data/accessTokens.go @@ -25,8 +25,7 @@ func createAccessTokensTable() { log.Fatal(err) } defer stmt.Close() - _, err = stmt.Exec() - if err != nil { + if _, err := stmt.Exec(); err != nil { log.Warnln(err) } } @@ -48,7 +47,7 @@ func InsertToken(token string, name string, scopes []string) error { } defer stmt.Close() - if _, err = stmt.Exec(token, name, scopesString); err != nil { + if _, err := stmt.Exec(token, name, scopesString); err != nil { return err } diff --git a/core/data/data_test.go b/core/data/data_test.go index 2b7891933..f5d277d0f 100644 --- a/core/data/data_test.go +++ b/core/data/data_test.go @@ -16,8 +16,7 @@ func TestString(t *testing.T) { const testKey = "test string key" const testValue = "test string value" - err := _datastore.SetString(testKey, testValue) - if err != nil { + if err := _datastore.SetString(testKey, testValue); err != nil { panic(err) } diff --git a/core/data/webhooks.go b/core/data/webhooks.go index 7e1c1ec91..8717401fb 100644 --- a/core/data/webhooks.go +++ b/core/data/webhooks.go @@ -26,8 +26,7 @@ func createWebhooksTable() { log.Fatal(err) } defer stmt.Close() - _, err = stmt.Exec() - if err != nil { + if _, err = stmt.Exec(); err != nil { log.Warnln(err) } } @@ -126,8 +125,7 @@ func GetWebhooksForEvent(event models.EventType) []models.Webhook { for rows.Next() { var url string - err = rows.Scan(&url, &event) - if err != nil { + if err := rows.Scan(&url, &event); err != nil { log.Debugln(err) log.Error("There is a problem with the database.") break diff --git a/core/storageproviders/local.go b/core/storageproviders/local.go index 1da93d6b4..a447ee697 100644 --- a/core/storageproviders/local.go +++ b/core/storageproviders/local.go @@ -32,16 +32,14 @@ func (s *LocalStorage) Setup() error { // SegmentWritten is called when a single segment of video is written. func (s *LocalStorage) SegmentWritten(localFilePath string) { - _, err := s.Save(localFilePath, 0) - if err != nil { + if _, err := s.Save(localFilePath, 0); err != nil { log.Warnln(err) } } // VariantPlaylistWritten is called when a variant hls playlist is written. func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) { - _, err := s.Save(localFilePath, 0) - if err != nil { + if _, err := s.Save(localFilePath, 0); err != nil { log.Errorln(err) return } @@ -49,8 +47,7 @@ func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) { // MasterPlaylistWritten is called when the master hls playlist is written. func (s *LocalStorage) MasterPlaylistWritten(localFilePath string) { - _, err := s.Save(localFilePath, 0) - if err != nil { + if _, err := s.Save(localFilePath, 0); err != nil { log.Warnln(err) } } diff --git a/core/storageproviders/s3Storage.go b/core/storageproviders/s3Storage.go index 6edff0d92..99f8a6ddf 100644 --- a/core/storageproviders/s3Storage.go +++ b/core/storageproviders/s3Storage.go @@ -74,8 +74,7 @@ func (s *S3Storage) SegmentWritten(localFilePath string) { utils.StartPerformanceMonitor(performanceMonitorKey) // Upload the segment - _, err := s.Save(localFilePath, 0) - if err != nil { + if _, err := s.Save(localFilePath, 0); err != nil { log.Errorln(err) return } @@ -92,8 +91,7 @@ func (s *S3Storage) SegmentWritten(localFilePath string) { // so the segments and the HLS playlist referencing // them are in sync. playlistPath := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8") - _, err = s.Save(playlistPath, 0) - if err != nil { + if _, err := s.Save(playlistPath, 0); err != nil { _queuedPlaylistUpdates[playlistPath] = playlistPath if pErr, ok := err.(*os.PathError); ok { log.Debugln(pErr.Path, "does not yet exist locally when trying to upload to S3 storage.") @@ -108,8 +106,7 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) { // to make sure we're not referring to files in a playlist that don't // yet exist. See SegmentWritten. if _, ok := _queuedPlaylistUpdates[localFilePath]; ok { - _, err := s.Save(localFilePath, 0) - if err != nil { + if _, err := s.Save(localFilePath, 0); err != nil { log.Errorln(err) _queuedPlaylistUpdates[localFilePath] = localFilePath } @@ -120,8 +117,7 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) { // MasterPlaylistWritten is called when the master hls playlist is written. func (s *S3Storage) MasterPlaylistWritten(localFilePath string) { // Rewrite the playlist to use absolute remote S3 URLs - err := s.rewriteRemotePlaylist(localFilePath) - if err != nil { + if err := s.rewriteRemotePlaylist(localFilePath); err != nil { log.Warnln(err) } } @@ -195,8 +191,7 @@ func (s *S3Storage) rewriteRemotePlaylist(filePath string) error { } p := m3u8.NewMasterPlaylist() - err = p.DecodeFrom(bufio.NewReader(f), false) - if err != nil { + if err := p.DecodeFrom(bufio.NewReader(f), false); err != nil { log.Warnln(err) } diff --git a/core/streamState.go b/core/streamState.go index 0b13f7749..b95fb243c 100644 --- a/core/streamState.go +++ b/core/streamState.go @@ -94,12 +94,10 @@ func SetStreamAsDisconnected() { playlistFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/stream.m3u8"), index) segmentFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/%s"), index, offlineFilename) - err := utils.Copy(offlineFilePath, segmentFilePath) - if err != nil { + if err := utils.Copy(offlineFilePath, segmentFilePath); err != nil { log.Warnln(err) } - _, err = _storage.Save(segmentFilePath, 0) - if err != nil { + if _, err := _storage.Save(segmentFilePath, 0); err != nil { log.Warnln(err) } if utils.DoesFileExists(playlistFilePath) { @@ -119,16 +117,13 @@ func SetStreamAsDisconnected() { variantPlaylist.Segments = variantPlaylist.Segments[:len(variantPlaylist.Segments)] } - err = variantPlaylist.Append(offlineFilename, 8.0, "") - if err != nil { + if err := variantPlaylist.Append(offlineFilename, 8.0, ""); err != nil { log.Fatalln(err) } - err = variantPlaylist.SetDiscontinuity() - if err != nil { + if err := variantPlaylist.SetDiscontinuity(); err != nil { log.Fatalln(err) } - _, err = f.WriteAt(variantPlaylist.Encode().Bytes(), 0) - if err != nil { + if _, err := f.WriteAt(variantPlaylist.Encode().Bytes(), 0); err != nil { log.Errorln(err) } } else { @@ -138,8 +133,7 @@ func SetStreamAsDisconnected() { } // If "offline" content gets changed then change the duration below - err = p.Append(offlineFilename, 8.0, "") - if err != nil { + if err := p.Append(offlineFilename, 8.0, ""); err != nil { log.Errorln(err) } @@ -149,13 +143,11 @@ func SetStreamAsDisconnected() { log.Errorln(err) } defer f.Close() - _, err = f.Write(p.Encode().Bytes()) - if err != nil { + if _, err := f.Write(p.Encode().Bytes()); err != nil { log.Errorln(err) } } - _, err = _storage.Save(playlistFilePath, 0) - if err != nil { + if _, err := _storage.Save(playlistFilePath, 0); err != nil { log.Warnln(err) } } diff --git a/core/transcoder/fileWriterReceiverService.go b/core/transcoder/fileWriterReceiverService.go index c6b2059a2..02e983d4f 100644 --- a/core/transcoder/fileWriterReceiverService.go +++ b/core/transcoder/fileWriterReceiverService.go @@ -74,8 +74,7 @@ func (s *FileWriterReceiverService) uploadHandler(w http.ResponseWriter, r *http } defer f.Close() - _, err = f.Write(data) - if err != nil { + if _, err := f.Write(data); err != nil { returnError(err, w) return } diff --git a/core/transcoder/transcoder.go b/core/transcoder/transcoder.go index 4cb8a47a9..a2ae7cbda 100644 --- a/core/transcoder/transcoder.go +++ b/core/transcoder/transcoder.go @@ -99,7 +99,7 @@ func (t *Transcoder) Start() { _commandExec = exec.Command("sh", "-c", command) if t.stdin != nil { - _commandExec.Stdin = t.stdin + _commandExec.Stdin = t.stdin } stdout, err := _commandExec.StderrPipe() @@ -107,8 +107,7 @@ func (t *Transcoder) Start() { panic(err) } - err = _commandExec.Start() - if err != nil { + if err := _commandExec.Start(); err != nil { log.Errorln("Transcoder error. See ", logging.GetTranscoderLogFilePath(), " for full output to debug.") log.Panicln(err, command) } diff --git a/core/transcoder/utils.go b/core/transcoder/utils.go index 06376a835..2ab1845f3 100644 --- a/core/transcoder/utils.go +++ b/core/transcoder/utils.go @@ -94,31 +94,27 @@ func createVariantDirectories() { // Create private hls data dirs utils.CleanupDirectory(config.PublicHLSStoragePath) utils.CleanupDirectory(config.PrivateHLSStoragePath) - + if len(data.GetStreamOutputVariants()) != 0 { for index := range data.GetStreamOutputVariants() { - err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777) - if err != nil { + if err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777); err != nil { log.Fatalln(err) } dir := path.Join(config.PublicHLSStoragePath, strconv.Itoa(index)) log.Traceln("Creating", dir) - err = os.MkdirAll(dir, 0777) - if err != nil { + if err := os.MkdirAll(dir, 0777); err != nil { log.Fatalln(err) } } } else { dir := path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)) log.Traceln("Creating", dir) - err := os.MkdirAll(dir, 0777) - if err != nil { + if err := os.MkdirAll(dir, 0777); err != nil { log.Fatalln(err) } dir = path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)) log.Traceln("Creating", dir) - err = os.MkdirAll(dir, 0777) - if err != nil { + if err := os.MkdirAll(dir, 0777); err != nil { log.Fatalln(err) } } diff --git a/main.go b/main.go index 777b6980e..1ef788a82 100644 --- a/main.go +++ b/main.go @@ -75,8 +75,7 @@ func main() { go metrics.Start() - err := data.SetupPersistence(config.DatabaseFilePath) - if err != nil { + if err := data.SetupPersistence(config.DatabaseFilePath); err != nil { log.Fatalln("failed to open database", err) } diff --git a/router/router.go b/router/router.go index e44c08301..2c434f94f 100644 --- a/router/router.go +++ b/router/router.go @@ -32,8 +32,7 @@ func Start() error { // websocket chat server go func() { - err := chat.Start() - if err != nil { + if err := chat.Start(); err != nil { log.Fatalln(err) } }() diff --git a/utils/accessTokens_test.go b/utils/accessTokens_test.go index ce09d2845..ecbb849f1 100644 --- a/utils/accessTokens_test.go +++ b/utils/accessTokens_test.go @@ -5,8 +5,7 @@ import ( ) func TestCreateAccessToken(t *testing.T) { - _, err := GenerateAccessToken() - if err != nil { + if _, err := GenerateAccessToken(); err != nil { t.Error(err) } } diff --git a/utils/backup.go b/utils/backup.go index e485fca9e..ab7a8010a 100644 --- a/utils/backup.go +++ b/utils/backup.go @@ -49,8 +49,7 @@ func Restore(backupFile string, databaseFile string) error { if err != nil { return err } - _, err = db.Exec(rawSql) - if err != nil { + if _, err := db.Exec(rawSql); err != nil { return err } diff --git a/utils/utils.go b/utils/utils.go index 5eecfd06c..6d73bcc2a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -161,8 +161,7 @@ func GetCacheDurationSecondsForPath(filePath string) int { } func IsValidUrl(urlToTest string) bool { - _, err := url.ParseRequestURI(urlToTest) - if err != nil { + if _, err := url.ParseRequestURI(urlToTest); err != nil { return false } @@ -236,4 +235,4 @@ func CleanupDirectory(path string) { if err := os.MkdirAll(path, 0777); err != nil { log.Fatalln("Unable to create directory. Please check the ownership and permissions", err) } -} \ No newline at end of file +} diff --git a/yp/yp.go b/yp/yp.go index 8e639c9c0..516a6e87c 100644 --- a/yp/yp.go +++ b/yp/yp.go @@ -113,8 +113,7 @@ func (yp *YP) ping() { } pingResponse := ypPingResponse{} - err = json.Unmarshal(body, &pingResponse) - if err != nil { + if err := json.Unmarshal(body, &pingResponse); err != nil { log.Errorln(err) }