mirror of
https://github.com/owncast/owncast.git
synced 2025-11-01 02:44:31 +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()
|
defer lock.Unlock()
|
||||||
|
|
||||||
if len(pendingAuthRequests)+1 > maxPendingRequests {
|
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()
|
code, _ := createCode()
|
||||||
|
|||||||
@ -100,13 +100,13 @@ func newEmojis(emotes ...emojiDef.Emoji) emojiDef.Emojis {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
func (e *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
||||||
v, ok := self.names[strings.ToLower(shortName)]
|
v, ok := e.names[strings.ToLower(shortName)]
|
||||||
if ok {
|
if ok {
|
||||||
return v, ok
|
return v, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, child := range self.children {
|
for _, child := range e.children {
|
||||||
v, ok := child.Get(shortName)
|
v, ok := child.Get(shortName)
|
||||||
if ok {
|
if ok {
|
||||||
return v, ok
|
return v, ok
|
||||||
@ -116,18 +116,18 @@ func (self *emojis) Get(shortName string) (*emojiDef.Emoji, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *emojis) Add(emotes emojiDef.Emojis) {
|
func (e *emojis) Add(emotes emojiDef.Emojis) {
|
||||||
self.children = append(self.children, emotes)
|
e.children = append(e.children, emotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *emojis) Clone() emojiDef.Emojis {
|
func (e *emojis) Clone() emojiDef.Emojis {
|
||||||
clone := &emojis{
|
clone := &emojis{
|
||||||
list: self.list,
|
list: e.list,
|
||||||
names: self.names,
|
names: e.names,
|
||||||
children: make([]emojiDef.Emojis, len(self.children)),
|
children: make([]emojiDef.Emojis, len(e.children)),
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(clone.children, self.children)
|
copy(clone.children, e.children)
|
||||||
|
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ func (e *FediverseEngagementEvent) GetBroadcastPayload() EventPayload {
|
|||||||
"timestamp": e.Timestamp,
|
"timestamp": e.Timestamp,
|
||||||
"body": e.Body,
|
"body": e.Body,
|
||||||
"image": e.Image,
|
"image": e.Image,
|
||||||
"type": e.Event.Type,
|
"type": e.Type,
|
||||||
"title": e.UserAccountName,
|
"title": e.UserAccountName,
|
||||||
"link": e.Link,
|
"link": e.Link,
|
||||||
"user": EventPayload{
|
"user": EventPayload{
|
||||||
@ -33,5 +33,5 @@ func (e *FediverseEngagementEvent) GetBroadcastPayload() EventPayload {
|
|||||||
|
|
||||||
// GetMessageType will return the event type for this message.
|
// GetMessageType will return the event type for this message.
|
||||||
func (e *FediverseEngagementEvent) GetMessageType() EventType {
|
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)
|
w := flv.NewMuxer(rtmpIn)
|
||||||
|
|
||||||
for {
|
for _hasInboundRTMPConnection {
|
||||||
if !_hasInboundRTMPConnection {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we don't get a readable packet in 10 seconds give up and disconnect
|
// 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 {
|
if err := _rtmpConnection.SetReadDeadline(time.Now().Add(10 * time.Second)); err != nil {
|
||||||
log.Debugln(err)
|
log.Debugln(err)
|
||||||
|
|||||||
@ -20,7 +20,7 @@ var _getInboundDetailsFromMetadataRE = regexp.MustCompile(`\{(.*?)\}`)
|
|||||||
func getInboundDetailsFromMetadata(metadata []interface{}) (models.RTMPStreamMetadata, error) {
|
func getInboundDetailsFromMetadata(metadata []interface{}) (models.RTMPStreamMetadata, error) {
|
||||||
metadataComponentsString := fmt.Sprintf("%+v", metadata)
|
metadataComponentsString := fmt.Sprintf("%+v", metadata)
|
||||||
if !strings.Contains(metadataComponentsString, "onMetaData") {
|
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)
|
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 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
|
return response.Location, nil
|
||||||
|
|||||||
@ -13,16 +13,15 @@ import (
|
|||||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
"github.com/rifflock/lfshook"
|
"github.com/rifflock/lfshook"
|
||||||
"github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
logger "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxLogEntries = 500
|
const maxLogEntries = 500
|
||||||
|
|
||||||
// OCLogger represents the owncast internal logging.
|
// OCLogger represents the owncast internal logging.
|
||||||
type OCLogger struct {
|
type OCLogger struct {
|
||||||
Entries []logrus.Entry
|
Entries []log.Entry
|
||||||
Warnings []logrus.Entry
|
Warnings []log.Entry
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ func Setup(enableDebugOptions bool, enableVerboseLogging bool) {
|
|||||||
loggingDirectory := filepath.Dir(getLogFilePath())
|
loggingDirectory := filepath.Dir(getLogFilePath())
|
||||||
if !utils.DoesFileExists(loggingDirectory) {
|
if !utils.DoesFileExists(loggingDirectory) {
|
||||||
if err := os.Mkdir(loggingDirectory, 0o700); err != nil {
|
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{
|
logMapping := lfshook.WriterMap{
|
||||||
logrus.InfoLevel: writer,
|
log.InfoLevel: writer,
|
||||||
logrus.DebugLevel: writer,
|
log.DebugLevel: writer,
|
||||||
logrus.TraceLevel: writer,
|
log.TraceLevel: writer,
|
||||||
logrus.WarnLevel: writer,
|
log.WarnLevel: writer,
|
||||||
logrus.ErrorLevel: writer,
|
log.ErrorLevel: writer,
|
||||||
logrus.FatalLevel: writer,
|
log.FatalLevel: writer,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.AddHook(lfshook.NewHook(
|
log.AddHook(lfshook.NewHook(
|
||||||
logMapping,
|
logMapping,
|
||||||
&logger.TextFormatter{},
|
&log.TextFormatter{},
|
||||||
))
|
))
|
||||||
|
|
||||||
if enableVerboseLogging {
|
if enableVerboseLogging {
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
log.SetLevel(log.TraceLevel)
|
||||||
} else {
|
} else {
|
||||||
logrus.SetLevel(logrus.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to stdout console
|
// Write to stdout console
|
||||||
logger.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
|
|
||||||
// Write to our custom logging hook for the log API
|
// Write to our custom logging hook for the log API
|
||||||
_logger := new(OCLogger)
|
_logger := new(OCLogger)
|
||||||
logger.AddHook(_logger)
|
log.AddHook(_logger)
|
||||||
|
|
||||||
if enableDebugOptions {
|
if enableDebugOptions {
|
||||||
logrus.SetReportCaller(true)
|
log.SetReportCaller(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger = _logger
|
Logger = _logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire runs for every logging request.
|
// 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
|
// Store all log messages to return back in the logging API
|
||||||
l.mu.Lock()
|
l.mu.Lock()
|
||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
@ -94,7 +93,7 @@ func (l *OCLogger) Fire(e *logger.Entry) error {
|
|||||||
}
|
}
|
||||||
l.Entries = append(l.Entries, *e)
|
l.Entries = append(l.Entries, *e)
|
||||||
|
|
||||||
if e.Level <= logger.WarnLevel {
|
if e.Level <= log.WarnLevel {
|
||||||
if len(l.Warnings) > maxLogEntries {
|
if len(l.Warnings) > maxLogEntries {
|
||||||
l.Warnings = l.Warnings[1:]
|
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.
|
// Levels specifies what log levels we care about.
|
||||||
func (l *OCLogger) Levels() []logrus.Level {
|
func (l *OCLogger) Levels() []log.Level {
|
||||||
return logrus.AllLevels
|
return log.AllLevels
|
||||||
}
|
}
|
||||||
|
|
||||||
// AllEntries returns all entries that were logged.
|
// AllEntries returns all entries that were logged.
|
||||||
func (l *OCLogger) AllEntries() []*logrus.Entry {
|
func (l *OCLogger) AllEntries() []*log.Entry {
|
||||||
l.mu.RLock()
|
l.mu.RLock()
|
||||||
defer l.mu.RUnlock()
|
defer l.mu.RUnlock()
|
||||||
|
|
||||||
// Make a copy so the returned value won't race with future log requests
|
// Make a copy so the returned value won't race with future log requests
|
||||||
logCount := int(math.Min(float64(len(l.Entries)), maxLogEntries))
|
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++ {
|
for i := 0; i < len(entries); i++ {
|
||||||
// Make a copy, for safety
|
// Make a copy, for safety
|
||||||
entries[len(entries)-logCount:][i] = &l.Entries[i]
|
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.
|
// WarningEntries returns all warning or greater that were logged.
|
||||||
func (l *OCLogger) WarningEntries() []*logrus.Entry {
|
func (l *OCLogger) WarningEntries() []*log.Entry {
|
||||||
l.mu.RLock()
|
l.mu.RLock()
|
||||||
defer l.mu.RUnlock()
|
defer l.mu.RUnlock()
|
||||||
|
|
||||||
// Make a copy so the returned value won't race with future log requests
|
// Make a copy so the returned value won't race with future log requests
|
||||||
logCount := int(math.Min(float64(len(l.Warnings)), maxLogEntries))
|
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++ {
|
for i := 0; i < len(entries); i++ {
|
||||||
// Make a copy, for safety
|
// Make a copy, for safety
|
||||||
entries[len(entries)-logCount:][i] = &l.Warnings[i]
|
entries[len(entries)-logCount:][i] = &l.Warnings[i]
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
func GetURLParam(r *http.Request, key string) (value string, err error) {
|
func GetURLParam(r *http.Request, key string) (value string, err error) {
|
||||||
value = chi.URLParam(r, key)
|
value = chi.URLParam(r, key)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
err = errors.New("Request does not contain requested URL param")
|
err = errors.New("request does not contain requested URL param")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,23 +78,23 @@ func Move(source, destination string) error {
|
|||||||
func moveFallback(source, destination string) error {
|
func moveFallback(source, destination string) error {
|
||||||
inputFile, err := os.Open(source) // nolint: gosec
|
inputFile, err := os.Open(source) // nolint: gosec
|
||||||
if err != nil {
|
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
|
outputFile, err := os.Create(destination) // nolint: gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = inputFile.Close()
|
_ = 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()
|
defer outputFile.Close()
|
||||||
_, err = io.Copy(outputFile, inputFile)
|
_, err = io.Copy(outputFile, inputFile)
|
||||||
_ = inputFile.Close()
|
_ = inputFile.Close()
|
||||||
if err != nil {
|
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
|
// The copy was successful, so now delete the original file
|
||||||
err = os.Remove(source)
|
err = os.Remove(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed removing original file: %s", err)
|
return fmt.Errorf("failed removing original file: %s", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -438,13 +438,14 @@ func DecodeBase64Image(url string) (bytes []byte, extension string, err error) {
|
|||||||
|
|
||||||
contentType := strings.Split(splitHeader[1], ";")[0]
|
contentType := strings.Split(splitHeader[1], ";")[0]
|
||||||
|
|
||||||
if contentType == "image/svg+xml" {
|
switch contentType {
|
||||||
|
case "image/svg+xml":
|
||||||
extension = ".svg"
|
extension = ".svg"
|
||||||
} else if contentType == "image/gif" {
|
case "image/gif":
|
||||||
extension = ".gif"
|
extension = ".gif"
|
||||||
} else if contentType == "image/png" {
|
case "image/png":
|
||||||
extension = ".png"
|
extension = ".png"
|
||||||
} else if contentType == "image/jpeg" {
|
case "image/jpeg":
|
||||||
extension = ".jpeg"
|
extension = ".jpeg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/owncast/owncast/logging"
|
"github.com/owncast/owncast/logging"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,7 +48,7 @@ type logsResponse struct {
|
|||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromEntry(e *logrus.Entry) logsResponse {
|
func fromEntry(e *log.Entry) logsResponse {
|
||||||
return logsResponse{
|
return logsResponse{
|
||||||
Message: e.Message,
|
Message: e.Message,
|
||||||
Level: e.Level.String(),
|
Level: e.Level.String(),
|
||||||
|
|||||||
@ -11,14 +11,15 @@ import (
|
|||||||
|
|
||||||
// HandleAuthEndpoint will handle the IndieAuth auth endpoint.
|
// HandleAuthEndpoint will handle the IndieAuth auth endpoint.
|
||||||
func HandleAuthEndpoint(w http.ResponseWriter, r *http.Request) {
|
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.
|
// Require the GET request for IndieAuth to be behind admin login.
|
||||||
f := middleware.RequireAdminAuth(HandleAuthEndpointGet)
|
f := middleware.RequireAdminAuth(HandleAuthEndpointGet)
|
||||||
f(w, r)
|
f(w, r)
|
||||||
return
|
return
|
||||||
} else if r.Method == http.MethodPost {
|
case http.MethodPost:
|
||||||
HandleAuthEndpointPost(w, r)
|
HandleAuthEndpointPost(w, r)
|
||||||
} else {
|
default:
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,13 +71,14 @@ func Start(enableVerboseLogging bool) error {
|
|||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
|
|
||||||
m.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
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)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/embed/chat/" || r.URL.Path == "/embed/chat" {
|
case "/embed/chat/", "/embed/chat":
|
||||||
// Redirect /embed/chat
|
// Redirect /embed/chat
|
||||||
http.Redirect(w, r, "/embed/chat/readonly", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/embed/chat/readonly", http.StatusTemporaryRedirect)
|
||||||
} else {
|
default:
|
||||||
http2Handler.ServeHTTP(w, r)
|
http2Handler.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user