Variable collisions; Possible use of nil value (#256)

* Variable '*' collides with imported package name

* Variable 'error' collides with builtin interface

* '*' may have 'nil' or other unexpected value as its corresponding error variable may be not 'nil'
This commit is contained in:
bitspill
2020-10-16 15:04:31 -07:00
committed by GitHub
parent 3812e6345f
commit bfbac8cc57
10 changed files with 41 additions and 31 deletions

View File

@@ -50,6 +50,9 @@ func createTable(db *sql.DB) {
func addMessage(message models.ChatMessage) {
tx, err := _db.Begin()
if err != nil {
log.Fatal(err)
}
stmt, err := tx.Prepare("INSERT INTO messages(id, author, body, messageType, visible, timestamp) values(?, ?, ?, ?, ?, ?)")
if err != nil {
log.Fatal(err)

View File

@@ -69,9 +69,9 @@ func (v *VideoSize) getString() string {
func (t *Transcoder) Stop() {
log.Traceln("Transcoder STOP requested.")
error := _commandExec.Process.Kill()
if error != nil {
log.Errorln(error)
err := _commandExec.Process.Kill()
if err != nil {
log.Errorln(err)
}
}

View File

@@ -34,8 +34,8 @@ func Start() {
port := 1935
s := rtmp.NewServer()
var lis net.Listener
var error error
if lis, error = net.Listen("tcp", fmt.Sprintf(":%d", port)); error != nil {
var err error
if lis, err = net.Listen("tcp", fmt.Sprintf(":%d", port)); err != nil {
return
}
@@ -46,8 +46,8 @@ func Start() {
s.HandleConn = HandleConn
if error != nil {
log.Panicln(error)
if err != nil {
log.Panicln(err)
}
log.Infof("RTMP server is listening for incoming stream on port: %d", port)

View File

@@ -40,9 +40,9 @@ func (s *LocalStorage) SegmentWritten(localFilePath string) {
// VariantPlaylistWritten is called when a variant hls playlist is written
func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
_, error := s.Save(localFilePath, 0)
if error != nil {
log.Errorln(error)
_, err := s.Save(localFilePath, 0)
if err != nil {
log.Errorln(err)
return
}
}

View File

@@ -72,9 +72,9 @@ func (s *S3Storage) SegmentWritten(localFilePath string) {
utils.StartPerformanceMonitor(performanceMonitorKey)
// Upload the segment
_, error := s.Save(localFilePath, 0)
if error != nil {
log.Errorln(error)
_, err := s.Save(localFilePath, 0)
if err != nil {
log.Errorln(err)
return
}
averagePerformance := utils.GetAveragePerformance(performanceMonitorKey)
@@ -89,11 +89,11 @@ func (s *S3Storage) SegmentWritten(localFilePath string) {
// Upload the variant playlist for this segment
// so the segments and the HLS playlist referencing
// them are in sync.
playlist := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8")
_, error = s.Save(playlist, 0)
if error != nil {
_queuedPlaylistUpdates[playlist] = playlist
if pErr, ok := error.(*os.PathError); ok {
playlistPath := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8")
_, err = s.Save(playlistPath, 0)
if 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.")
return
}
@@ -106,9 +106,9 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) {
// to make sure we're not refering to files in a playlist that don't
// yet exist. See SegmentWritten.
if _, ok := _queuedPlaylistUpdates[localFilePath]; ok {
_, error := s.Save(localFilePath, 0)
if error != nil {
log.Errorln(error)
_, err := s.Save(localFilePath, 0)
if err != nil {
log.Errorln(err)
_queuedPlaylistUpdates[localFilePath] = localFilePath
}
delete(_queuedPlaylistUpdates, localFilePath)

View File

@@ -74,10 +74,10 @@ func SetStreamAsDisconnected() {
if utils.DoesFileExists(playlistFilePath) {
f, err := os.OpenFile(playlistFilePath, os.O_CREATE|os.O_RDWR, os.ModePerm)
defer f.Close()
if err != nil {
log.Errorln(err)
}
defer f.Close()
playlist, _, err := m3u8.DecodeFrom(bufio.NewReader(f), true)
variantPlaylist := playlist.(*m3u8.MediaPlaylist)