Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Some linter cleanup

Gabe Kangas915647fbd78f
diff --git a/.golangci.yml b/.golangci.yml
index 3088256819..4277d7b8a0 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -40,8 +40,44 @@ linters:
- unconvert
- unparam
- whitespace
-
+ - nakedret
+ - cyclop
+ - gosimple
+ - varcheck
+ - unused
+ - deadcode
+ - exportloopref
+ - gocritic
+ - forbidigo
+ - unparam
+ - wastedassign
linters-settings:
govet:
disable:
- composite
+
+ cyclop:
+ # the maximal code complexity to report. default is 10. eventually work our way to that.
+ max-complexity: 20
+ # the max average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0)
+ package-average: 0.0
+ # should ignore tests
+ skip-tests: true
+
+ gosimple:
+ # Select the Go version to target. The default is '1.13'.
+ go: "1.17"
+ # https://staticcheck.io/docs/options#checks
+ checks: ["all"]
+
+ gocritic:
+ disabled-checks:
+ - ifElseChain
+ - exitAfterDefer
+
+ forbidigo:
+ # Forbid the following identifiers (identifiers are written using regexp):
+ forbid:
+ # Logging via Print bypasses our logging framework.
+ - ^(fmt\.Print(|f|ln)|print|println)
+ - ^panic.*$
diff --git a/core/chat/chatclient.go b/core/chat/chatclient.go
index c0635989d4..d371d078cd 100644
--- a/core/chat/chatclient.go
+++ b/core/chat/chatclient.go
@@ -118,7 +118,7 @@ func (c *Client) readPump() {
continue
}
- message = bytes.TrimSpace(bytes.Replace(message, newline, space, -1))
+ message = bytes.TrimSpace(bytes.ReplaceAll(message, newline, space))
c.handleEvent(message)
}
}
diff --git a/core/chat/events.go b/core/chat/events.go
index 284a007c94..7e0d44cfa7 100644
--- a/core/chat/events.go
+++ b/core/chat/events.go
@@ -111,6 +111,6 @@ func (s *Server) userMessageSent(eventData chatClientEvent) {
SaveUserMessage(event)
- eventData.client.MessageCount = eventData.client.MessageCount + 1
+ eventData.client.MessageCount++
_lastSeenCache[event.User.ID] = time.Now()
}
diff --git a/core/chat/utils.go b/core/chat/utils.go
index 8fbebbe494..7ab6efea78 100644
--- a/core/chat/utils.go
+++ b/core/chat/utils.go
@@ -2,6 +2,7 @@ package chat
import (
"syscall"
+
log "github.com/sirupsen/logrus"
)
diff --git a/core/transcoder/thumbnailGenerator.go b/core/transcoder/thumbnailGenerator.go
index 21e6cd079d..e50c67fe85 100644
--- a/core/transcoder/thumbnailGenerator.go
+++ b/core/transcoder/thumbnailGenerator.go
@@ -132,10 +132,8 @@ func makeAnimatedGifPreview(sourceFile string, outputFile string) {
ffmpegCmd := strings.Join(animatedGifFlags, " ")
if _, err := exec.Command("sh", "-c", ffmpegCmd).Output(); err != nil {
log.Errorln(err)
- } else {
// rename temp file
- if err := os.Rename(outputFileTemp, outputFile); err != nil {
- log.Errorln(err)
- }
+ } else if err := os.Rename(outputFileTemp, outputFile); err != nil {
+ log.Errorln(err)
}
}
diff --git a/core/transcoder/transcoder.go b/core/transcoder/transcoder.go
index 4d0d168e2d..c8f3eb2cdc 100644
--- a/core/transcoder/transcoder.go
+++ b/core/transcoder/transcoder.go
@@ -284,9 +284,8 @@ func (t *Transcoder) getVariantsString() string {
for _, variant := range t.variants {
variantsCommandFlags = variantsCommandFlags + " " + variant.getVariantString(t)
- singleVariantMap := ""
- singleVariantMap = fmt.Sprintf("v:%d,a:%d ", variant.index, variant.index)
- variantsStreamMaps = variantsStreamMaps + singleVariantMap
+ singleVariantMap := fmt.Sprintf("v:%d,a:%d ", variant.index, variant.index)
+ variantsStreamMaps += singleVariantMap
}
variantsCommandFlags = variantsCommandFlags + " " + variantsStreamMaps + "\""
diff --git a/utils/performanceTimer.go b/utils/performanceTimer.go
index 689d9ffb84..30206c7a2f 100644
--- a/utils/performanceTimer.go
+++ b/utils/performanceTimer.go
@@ -52,7 +52,7 @@ func removeHighValue(values []float64) []float64 {
func avg(values []float64) float64 {
total := 0.0
for _, number := range values {
- total = total + number
+ total += number
}
average := total / float64(len(values))
return average
diff --git a/utils/phraseGenerator.go b/utils/phraseGenerator.go
index 7f5aa74183..7776b169a9 100644
--- a/utils/phraseGenerator.go
+++ b/utils/phraseGenerator.go
@@ -203,7 +203,7 @@ var (
// Subrahmanyan Chandrasekhar - Astrophysicist known for his mathematical theory on different stages and evolution in structures of the stars. He has won nobel prize for physics - https://en.wikipedia.org/wiki/Subrahmanyan_Chandrasekhar
"chandrasekhar",
- //Claude Shannon - The father of information theory and founder of digital circuit design theory. (https://en.wikipedia.org/wiki/Claude_Shannon)
+ // Claude Shannon - The father of information theory and founder of digital circuit design theory. (https://en.wikipedia.org/wiki/Claude_Shannon)
"shannon",
// Joan Clarke - Bletchley Park code breaker during the Second World War who pioneered techniques that remained top secret for decades. Also an accomplished numismatist https://en.wikipedia.org/wiki/Joan_Clarke
@@ -382,7 +382,7 @@ var (
// Henrietta Swan Leavitt - she was an American astronomer who discovered the relation between the luminosity and the period of Cepheid variable stars. https://en.wikipedia.org/wiki/Henrietta_Swan_Leavitt
"leavitt",
- //Daniel Lewin - Mathematician, Akamai co-founder, soldier, 9/11 victim-- Developed optimization techniques for routing traffic on the internet. Died attempting to stop the 9-11 hijackers. https://en.wikipedia.org/wiki/Daniel_Lewin
+ // Daniel Lewin - Mathematician, Akamai co-founder, soldier, 9/11 victim-- Developed optimization techniques for routing traffic on the internet. Died attempting to stop the 9-11 hijackers. https://en.wikipedia.org/wiki/Daniel_Lewin
"lewin",
// Ruth Lichterman - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Ruth_Teitelbaum
diff --git a/yp/yp.go b/yp/yp.go
index 2c82247bb5..facc676b61 100644
--- a/yp/yp.go
+++ b/yp/yp.go
@@ -21,7 +21,7 @@ const pingInterval = 4 * time.Minute
var getStatus func() models.Status
var _inErrorState = false
-//YP is a service for handling listing in the Owncast directory.
+// YP is a service for handling listing in the Owncast directory.
type YP struct {
timer *time.Ticker
}