mirror of
https://github.com/owncast/owncast.git
synced 2025-11-01 10:55:57 +08:00
Fix all golangci-lint warnings surfaced by v2.4.0 (#4567)
* Initial plan * Fix all golangci-lint warnings (21 issues resolved) Co-authored-by: gabek <414923+gabek@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gabek <414923+gabek@users.noreply.github.com>
This commit is contained in:
@ -68,7 +68,7 @@ func RegisterFediverseOTP(accessToken, userID, userDisplayName, account string)
|
||||
defer lock.Unlock()
|
||||
|
||||
if len(pendingAuthRequests)+1 > maxPendingRequests {
|
||||
return request, false, errors.New("Please try again later. Too many pending requests.")
|
||||
return request, false, errors.New("please try again later, too many pending requests")
|
||||
}
|
||||
|
||||
code, _ := createCode()
|
||||
|
||||
@ -100,13 +100,13 @@ func newEmojis(emotes ...emojiDef.Emoji) emojiDef.Emojis {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
||||
v, ok := self.names[strings.ToLower(shortName)]
|
||||
func (e *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
||||
v, ok := e.names[strings.ToLower(shortName)]
|
||||
if ok {
|
||||
return v, ok
|
||||
}
|
||||
|
||||
for _, child := range self.children {
|
||||
for _, child := range e.children {
|
||||
v, ok := child.Get(shortName)
|
||||
if ok {
|
||||
return v, ok
|
||||
@ -116,18 +116,18 @@ func (self *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (self *emojis) Add(emotes emojiDef.Emojis) {
|
||||
self.children = append(self.children, emotes)
|
||||
func (e *emojis) Add(emotes emojiDef.Emojis) {
|
||||
e.children = append(e.children, emotes)
|
||||
}
|
||||
|
||||
func (self *emojis) Clone() emojiDef.Emojis {
|
||||
func (e *emojis) Clone() emojiDef.Emojis {
|
||||
clone := &emojis{
|
||||
list: self.list,
|
||||
names: self.names,
|
||||
children: make([]emojiDef.Emojis, len(self.children)),
|
||||
list: e.list,
|
||||
names: e.names,
|
||||
children: make([]emojiDef.Emojis, len(e.children)),
|
||||
}
|
||||
|
||||
copy(clone.children, self.children)
|
||||
copy(clone.children, e.children)
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ func (e *FediverseEngagementEvent) GetBroadcastPayload() EventPayload {
|
||||
"timestamp": e.Timestamp,
|
||||
"body": e.Body,
|
||||
"image": e.Image,
|
||||
"type": e.Event.Type,
|
||||
"type": e.Type,
|
||||
"title": e.UserAccountName,
|
||||
"link": e.Link,
|
||||
"user": EventPayload{
|
||||
@ -33,5 +33,5 @@ func (e *FediverseEngagementEvent) GetBroadcastPayload() EventPayload {
|
||||
|
||||
// GetMessageType will return the event type for this message.
|
||||
func (e *FediverseEngagementEvent) GetMessageType() EventType {
|
||||
return e.Event.Type
|
||||
return e.Type
|
||||
}
|
||||
|
||||
@ -114,11 +114,7 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) {
|
||||
|
||||
w := flv.NewMuxer(rtmpIn)
|
||||
|
||||
for {
|
||||
if !_hasInboundRTMPConnection {
|
||||
break
|
||||
}
|
||||
|
||||
for _hasInboundRTMPConnection {
|
||||
// If we don't get a readable packet in 10 seconds give up and disconnect
|
||||
if err := _rtmpConnection.SetReadDeadline(time.Now().Add(10 * time.Second)); err != nil {
|
||||
log.Debugln(err)
|
||||
|
||||
@ -20,7 +20,7 @@ var _getInboundDetailsFromMetadataRE = regexp.MustCompile(`\{(.*?)\}`)
|
||||
func getInboundDetailsFromMetadata(metadata []interface{}) (models.RTMPStreamMetadata, error) {
|
||||
metadataComponentsString := fmt.Sprintf("%+v", metadata)
|
||||
if !strings.Contains(metadataComponentsString, "onMetaData") {
|
||||
return models.RTMPStreamMetadata{}, errors.New("Not a onMetaData message")
|
||||
return models.RTMPStreamMetadata{}, errors.New("not a onMetaData message")
|
||||
}
|
||||
|
||||
submatchall := _getInboundDetailsFromMetadataRE.FindAllString(metadataComponentsString, 1)
|
||||
|
||||
@ -203,7 +203,7 @@ func (s *S3Storage) Save(filePath string, retryCount int) (string, error) {
|
||||
return s.Save(filePath, retryCount+1)
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("Giving up uploading %s to object storage %s", filePath, s.s3Endpoint)
|
||||
return "", fmt.Errorf("giving up uploading %s to object storage %s", filePath, s.s3Endpoint)
|
||||
}
|
||||
|
||||
return response.Location, nil
|
||||
|
||||
@ -13,16 +13,15 @@ import (
|
||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
"github.com/owncast/owncast/utils"
|
||||
"github.com/rifflock/lfshook"
|
||||
"github.com/sirupsen/logrus"
|
||||
logger "github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const maxLogEntries = 500
|
||||
|
||||
// OCLogger represents the owncast internal logging.
|
||||
type OCLogger struct {
|
||||
Entries []logrus.Entry
|
||||
Warnings []logrus.Entry
|
||||
Entries []log.Entry
|
||||
Warnings []log.Entry
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
@ -35,7 +34,7 @@ func Setup(enableDebugOptions bool, enableVerboseLogging bool) {
|
||||
loggingDirectory := filepath.Dir(getLogFilePath())
|
||||
if !utils.DoesFileExists(loggingDirectory) {
|
||||
if err := os.Mkdir(loggingDirectory, 0o700); err != nil {
|
||||
logger.Errorln("unable to create logs directory", loggingDirectory, err)
|
||||
log.Errorln("unable to create logs directory", loggingDirectory, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,41 +48,41 @@ func Setup(enableDebugOptions bool, enableVerboseLogging bool) {
|
||||
)
|
||||
|
||||
logMapping := lfshook.WriterMap{
|
||||
logrus.InfoLevel: writer,
|
||||
logrus.DebugLevel: writer,
|
||||
logrus.TraceLevel: writer,
|
||||
logrus.WarnLevel: writer,
|
||||
logrus.ErrorLevel: writer,
|
||||
logrus.FatalLevel: writer,
|
||||
log.InfoLevel: writer,
|
||||
log.DebugLevel: writer,
|
||||
log.TraceLevel: writer,
|
||||
log.WarnLevel: writer,
|
||||
log.ErrorLevel: writer,
|
||||
log.FatalLevel: writer,
|
||||
}
|
||||
|
||||
logger.AddHook(lfshook.NewHook(
|
||||
log.AddHook(lfshook.NewHook(
|
||||
logMapping,
|
||||
&logger.TextFormatter{},
|
||||
&log.TextFormatter{},
|
||||
))
|
||||
|
||||
if enableVerboseLogging {
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
log.SetLevel(log.TraceLevel)
|
||||
} else {
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
|
||||
// Write to stdout console
|
||||
logger.SetOutput(os.Stdout)
|
||||
log.SetOutput(os.Stdout)
|
||||
|
||||
// Write to our custom logging hook for the log API
|
||||
_logger := new(OCLogger)
|
||||
logger.AddHook(_logger)
|
||||
log.AddHook(_logger)
|
||||
|
||||
if enableDebugOptions {
|
||||
logrus.SetReportCaller(true)
|
||||
log.SetReportCaller(true)
|
||||
}
|
||||
|
||||
Logger = _logger
|
||||
}
|
||||
|
||||
// Fire runs for every logging request.
|
||||
func (l *OCLogger) Fire(e *logger.Entry) error {
|
||||
func (l *OCLogger) Fire(e *log.Entry) error {
|
||||
// Store all log messages to return back in the logging API
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
@ -94,7 +93,7 @@ func (l *OCLogger) Fire(e *logger.Entry) error {
|
||||
}
|
||||
l.Entries = append(l.Entries, *e)
|
||||
|
||||
if e.Level <= logger.WarnLevel {
|
||||
if e.Level <= log.WarnLevel {
|
||||
if len(l.Warnings) > maxLogEntries {
|
||||
l.Warnings = l.Warnings[1:]
|
||||
}
|
||||
@ -105,18 +104,18 @@ func (l *OCLogger) Fire(e *logger.Entry) error {
|
||||
}
|
||||
|
||||
// Levels specifies what log levels we care about.
|
||||
func (l *OCLogger) Levels() []logrus.Level {
|
||||
return logrus.AllLevels
|
||||
func (l *OCLogger) Levels() []log.Level {
|
||||
return log.AllLevels
|
||||
}
|
||||
|
||||
// AllEntries returns all entries that were logged.
|
||||
func (l *OCLogger) AllEntries() []*logrus.Entry {
|
||||
func (l *OCLogger) AllEntries() []*log.Entry {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
// Make a copy so the returned value won't race with future log requests
|
||||
logCount := int(math.Min(float64(len(l.Entries)), maxLogEntries))
|
||||
entries := make([]*logrus.Entry, logCount)
|
||||
entries := make([]*log.Entry, logCount)
|
||||
for i := 0; i < len(entries); i++ {
|
||||
// Make a copy, for safety
|
||||
entries[len(entries)-logCount:][i] = &l.Entries[i]
|
||||
@ -126,13 +125,13 @@ func (l *OCLogger) AllEntries() []*logrus.Entry {
|
||||
}
|
||||
|
||||
// WarningEntries returns all warning or greater that were logged.
|
||||
func (l *OCLogger) WarningEntries() []*logrus.Entry {
|
||||
func (l *OCLogger) WarningEntries() []*log.Entry {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
|
||||
// Make a copy so the returned value won't race with future log requests
|
||||
logCount := int(math.Min(float64(len(l.Warnings)), maxLogEntries))
|
||||
entries := make([]*logrus.Entry, logCount)
|
||||
entries := make([]*log.Entry, logCount)
|
||||
for i := 0; i < len(entries); i++ {
|
||||
// Make a copy, for safety
|
||||
entries[len(entries)-logCount:][i] = &l.Warnings[i]
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
func GetURLParam(r *http.Request, key string) (value string, err error) {
|
||||
value = chi.URLParam(r, key)
|
||||
if value == "" {
|
||||
err = errors.New("Request does not contain requested URL param")
|
||||
err = errors.New("request does not contain requested URL param")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -78,23 +78,23 @@ func Move(source, destination string) error {
|
||||
func moveFallback(source, destination string) error {
|
||||
inputFile, err := os.Open(source) // nolint: gosec
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't open source file: %s", err)
|
||||
return fmt.Errorf("couldn't open source file: %s", err)
|
||||
}
|
||||
outputFile, err := os.Create(destination) // nolint: gosec
|
||||
if err != nil {
|
||||
_ = inputFile.Close()
|
||||
return fmt.Errorf("Couldn't open dest file: %s", err)
|
||||
return fmt.Errorf("couldn't open dest file: %s", err)
|
||||
}
|
||||
defer outputFile.Close()
|
||||
_, err = io.Copy(outputFile, inputFile)
|
||||
_ = inputFile.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Writing to output file failed: %s", err)
|
||||
return fmt.Errorf("writing to output file failed: %s", err)
|
||||
}
|
||||
// The copy was successful, so now delete the original file
|
||||
err = os.Remove(source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed removing original file: %s", err)
|
||||
return fmt.Errorf("failed removing original file: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -438,13 +438,14 @@ func DecodeBase64Image(url string) (bytes []byte, extension string, err error) {
|
||||
|
||||
contentType := strings.Split(splitHeader[1], ";")[0]
|
||||
|
||||
if contentType == "image/svg+xml" {
|
||||
switch contentType {
|
||||
case "image/svg+xml":
|
||||
extension = ".svg"
|
||||
} else if contentType == "image/gif" {
|
||||
case "image/gif":
|
||||
extension = ".gif"
|
||||
} else if contentType == "image/png" {
|
||||
case "image/png":
|
||||
extension = ".png"
|
||||
} else if contentType == "image/jpeg" {
|
||||
case "image/jpeg":
|
||||
extension = ".jpeg"
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/owncast/owncast/logging"
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -49,7 +48,7 @@ type logsResponse struct {
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
func fromEntry(e *logrus.Entry) logsResponse {
|
||||
func fromEntry(e *log.Entry) logsResponse {
|
||||
return logsResponse{
|
||||
Message: e.Message,
|
||||
Level: e.Level.String(),
|
||||
|
||||
@ -11,14 +11,15 @@ import (
|
||||
|
||||
// HandleAuthEndpoint will handle the IndieAuth auth endpoint.
|
||||
func HandleAuthEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
// Require the GET request for IndieAuth to be behind admin login.
|
||||
f := middleware.RequireAdminAuth(HandleAuthEndpointGet)
|
||||
f(w, r)
|
||||
return
|
||||
} else if r.Method == http.MethodPost {
|
||||
case http.MethodPost:
|
||||
HandleAuthEndpointPost(w, r)
|
||||
} else {
|
||||
default:
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
@ -71,13 +71,14 @@ func Start(enableVerboseLogging bool) error {
|
||||
m := http.NewServeMux()
|
||||
|
||||
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/debug/vars" {
|
||||
switch r.URL.Path {
|
||||
case "/debug/vars":
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
} else if r.URL.Path == "/embed/chat/" || r.URL.Path == "/embed/chat" {
|
||||
case "/embed/chat/", "/embed/chat":
|
||||
// Redirect /embed/chat
|
||||
http.Redirect(w, r, "/embed/chat/readonly", http.StatusTemporaryRedirect)
|
||||
} else {
|
||||
default:
|
||||
http2Handler.ServeHTTP(w, r)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user