From 12104978e8369906c0cfa6b18bf5a3c0ee6173d5 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 29 Jun 2021 10:21:00 -0700 Subject: [PATCH] Some linter cleanup --- config/config.go | 2 +- config/verifyInstall.go | 2 +- controllers/admin/config.go | 6 ++---- controllers/video.go | 2 +- core/data/config.go | 6 +++--- core/streamState.go | 2 +- core/transcoder/hlsFilesystemCleanup.go | 2 +- logging/logging.go | 5 +++-- main.go | 5 +++-- utils/backup.go | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/config/config.go b/config/config.go index 34c2c4427..a0b067386 100644 --- a/config/config.go +++ b/config/config.go @@ -10,7 +10,7 @@ import ( // DatabaseFilePath is the path to the file ot be used as the global database for this run of the application. var DatabaseFilePath = "data/owncast.db" -// LogDirectory is the path to various log files +// LogDirectory is the path to various log files. var LogDirectory = "./data/logs" // EnableDebugFeatures will print additional data to help in debugging. diff --git a/config/verifyInstall.go b/config/verifyInstall.go index 5a8250a05..b6b5716a3 100644 --- a/config/verifyInstall.go +++ b/config/verifyInstall.go @@ -52,7 +52,7 @@ func VerifyFFMpegPath(path string) error { versionString := "v" + strings.Split(fullVersionString, "-")[0] - // Some builds of ffmpeg have wierd build numbers that we can't parse + // Some builds of ffmpeg have weird build numbers that we can't parse if !semver.IsValid(versionString) { log.Debugf("unable to determine if ffmpeg version %s is recent enough. if you experience issues with video you may want to look into updating", fullVersionString) return nil diff --git a/controllers/admin/config.go b/controllers/admin/config.go index 734181f3f..e926e0ad5 100644 --- a/controllers/admin/config.go +++ b/controllers/admin/config.go @@ -35,7 +35,7 @@ func SetTags(w http.ResponseWriter, r *http.Request) { return } - var tagStrings []string + tagStrings := make([]string, 0) for _, tag := range configValues { tagStrings = append(tagStrings, tag.Value.(string)) } @@ -226,7 +226,7 @@ func SetLogo(w http.ResponseWriter, r *http.Request) { } imgPath := filepath.Join("data", "logo"+extension) - if err := ioutil.WriteFile(imgPath, bytes, 0644); err != nil { + if err := ioutil.WriteFile(imgPath, bytes, 0600); err != nil { controllers.WriteSimpleResponse(w, false, err.Error()) return } @@ -434,7 +434,6 @@ func SetS3Configuration(w http.ResponseWriter, r *http.Request) { if newS3Config.Value.Endpoint == "" || !utils.IsValidUrl((newS3Config.Value.Endpoint)) { controllers.WriteSimpleResponse(w, false, "s3 support requires an endpoint") return - } if newS3Config.Value.AccessKey == "" || newS3Config.Value.Secret == "" { @@ -455,7 +454,6 @@ func SetS3Configuration(w http.ResponseWriter, r *http.Request) { data.SetS3Config(newS3Config.Value) controllers.WriteSimpleResponse(w, true, "storage configuration changed") - } // SetStreamOutputVariants will handle the web config request to set the video output stream variants. diff --git a/controllers/video.go b/controllers/video.go index 6cdca3a91..80c9bed45 100644 --- a/controllers/video.go +++ b/controllers/video.go @@ -15,7 +15,7 @@ type variantsResponse struct { Index int `json:"index"` } -// GetVideoStreamOutputVariants will return the video variants available, +// GetVideoStreamOutputVariants will return the video variants available. func GetVideoStreamOutputVariants(w http.ResponseWriter, r *http.Request) { outputVariants := data.GetStreamOutputVariants() result := make([]variantsResponse, len(outputVariants)) diff --git a/core/data/config.go b/core/data/config.go index d46f5d5b0..12f538487 100644 --- a/core/data/config.go +++ b/core/data/config.go @@ -199,7 +199,7 @@ func GetHTTPListenAddress() string { log.Traceln(httpListenAddressKey, err) return config.GetDefaults().WebServerIP } - return string(address) + return address } // SetHTTPListenAddress will set the server HTTP listen address. @@ -577,7 +577,7 @@ func FindHighestVideoQualityIndex(qualities []models.StreamOutputVariant) int { return indexedQualities[0].index } -// GetUsernameBlocklist will return the blocked usernames as a comma seperated string. +// GetUsernameBlocklist will return the blocked usernames as a comma separated string. func GetUsernameBlocklist() string { usernameString, err := _datastore.GetString(blockedUsernamesKey) @@ -589,7 +589,7 @@ func GetUsernameBlocklist() string { return usernameString } -// SetUsernameBlocklist set the username blocklist as a comma seperated string. +// SetUsernameBlocklist set the username blocklist as a comma separated string. func SetUsernameBlocklist(usernames string) error { return _datastore.SetString(blockedUsernamesKey, usernames) } diff --git a/core/streamState.go b/core/streamState.go index b796c21e7..7f409ff7a 100644 --- a/core/streamState.go +++ b/core/streamState.go @@ -113,7 +113,7 @@ func SetStreamAsDisconnected() { } variantPlaylist := playlist.(*m3u8.MediaPlaylist) - if len(variantPlaylist.Segments) > int(data.GetStreamLatencyLevel().SegmentCount) { + if len(variantPlaylist.Segments) > data.GetStreamLatencyLevel().SegmentCount { variantPlaylist.Segments = variantPlaylist.Segments[:len(variantPlaylist.Segments)] } diff --git a/core/transcoder/hlsFilesystemCleanup.go b/core/transcoder/hlsFilesystemCleanup.go index a13a43cff..93bfdbbff 100644 --- a/core/transcoder/hlsFilesystemCleanup.go +++ b/core/transcoder/hlsFilesystemCleanup.go @@ -14,7 +14,7 @@ import ( // in the stream. func CleanupOldContent(baseDirectory string) { // Determine how many files we should keep on disk - maxNumber := int(data.GetStreamLatencyLevel().SegmentCount) + maxNumber := data.GetStreamLatencyLevel().SegmentCount buffer := 10 files, err := getAllFilesRecursive(baseDirectory) diff --git a/logging/logging.go b/logging/logging.go index 246b4060b..a49db0b8b 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -25,13 +25,14 @@ type OCLogger struct { } var Logger *OCLogger -var _level logrus.Level // Setup configures our custom logging destinations. func Setup(enableDebugOptions bool, enableVerboseLogging bool) { // Create the logging directory if needed if !utils.DoesFileExists(getLogFilePath()) { - os.Mkdir(getLogFilePath(), 0700) + if err := os.Mkdir(getLogFilePath(), 0700); err != nil { + logger.Errorln("unable to create directory", getLogFilePath(), err) + } } // Write logs to a file diff --git a/main.go b/main.go index b936353e7..777b6980e 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,6 @@ import ( ) func main() { - // Enable bundling of admin assets _ = pkger.Include("/admin") @@ -48,7 +47,9 @@ func main() { // Create the data directory if needed if !utils.DoesFileExists("data") { - os.Mkdir("./data", 0700) + if err := os.Mkdir("./data", 0700); err != nil { + log.Fatalln("Cannot create data directory", err) + } } // Allows a user to restore a specific database backup diff --git a/utils/backup.go b/utils/backup.go index 19edde1ae..e485fca9e 100644 --- a/utils/backup.go +++ b/utils/backup.go @@ -22,18 +22,18 @@ func Restore(backupFile string, databaseFile string) error { data, err := ioutil.ReadFile(backupFile) if err != nil { - return errors.New(fmt.Sprintf("Unable to read backup file %s", err)) + return fmt.Errorf("Unable to read backup file %s", err) } gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return errors.New(fmt.Sprintf("Unable to read backup file %s", err)) + return fmt.Errorf("Unable to read backup file %s", err) } defer gz.Close() var b bytes.Buffer if _, err := io.Copy(&b, gz); err != nil { - return errors.New(fmt.Sprintf("Unable to read backup file %s", err)) + return fmt.Errorf("Unable to read backup file %s", err) } defer gz.Close()