Skip to content

Commit

Permalink
Merge pull request #456 from Unpackerr/dn2_lint
Browse files Browse the repository at this point in the history
lint some things
  • Loading branch information
davidnewhall authored Jul 13, 2024
2 parents 656654d + 8c2c45b commit d113a97
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 98 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ linters:
- varnamelen
- tagliatelle
- cyclop
- tagalign
- depguard
- testpackage
run:
Expand Down
8 changes: 4 additions & 4 deletions pkg/bindata/bindata.go

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions pkg/unpackerr/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,39 @@ var (
//
//nolint:lll
type Config struct {
Debug bool `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
Quiet bool `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
Activity bool `json:"activity" toml:"activity" xml:"activity" yaml:"activity"`
Parallel uint `json:"parallel" toml:"parallel" xml:"parallel" yaml:"parallel"`
ErrorStdErr bool `json:"errorStderr" toml:"error_stderr" xml:"error_stderr" yaml:"errorStderr"`
LogFile string `json:"logFile" toml:"log_file" xml:"log_file" yaml:"logFile"`
LogFiles int `json:"logFiles" toml:"log_files" xml:"log_files" yaml:"logFiles"`
LogFileMb int `json:"logFileMb" toml:"log_file_mb" xml:"log_file_mb" yaml:"logFileMb"`
MaxRetries uint `json:"maxRetries" toml:"max_retries" xml:"max_retries" yaml:"maxRetries"`
FileMode string `json:"fileMode" toml:"file_mode" xml:"file_mode" yaml:"fileMode"`
DirMode string `json:"dirMode" toml:"dir_mode" xml:"dir_mode" yaml:"dirMode"`
LogQueues cnfg.Duration `json:"logQueues" toml:"log_queues" xml:"log_queues" yaml:"logQueues"`
Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval" yaml:"interval"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
DeleteDelay cnfg.Duration `json:"deleteDelay" toml:"delete_delay" xml:"delete_delay" yaml:"deleteDelay"`
StartDelay cnfg.Duration `json:"startDelay" toml:"start_delay" xml:"start_delay" yaml:"startDelay"`
RetryDelay cnfg.Duration `json:"retryDelay" toml:"retry_delay" xml:"retry_delay" yaml:"retryDelay"`
KeepHistory uint `json:"keepHistory" toml:"keep_history" xml:"keep_history" yaml:"keepHistory"` // undocumented.
Passwords StringSlice `json:"passwords" toml:"passwords" xml:"password" yaml:"passwords"`
Webserver *WebServer `json:"webserver" toml:"webserver" xml:"webserver" yaml:"webserver"`
Lidarr []*LidarrConfig `json:"lidarr,omitempty" toml:"lidarr" xml:"lidarr" yaml:"lidarr,omitempty"`
Radarr []*RadarrConfig `json:"radarr,omitempty" toml:"radarr" xml:"radarr" yaml:"radarr,omitempty"`
Whisparr []*RadarrConfig `json:"whisparr,omitempty" toml:"whisparr" xml:"whisparr" yaml:"whisparr,omitempty"`
Readarr []*ReadarrConfig `json:"readarr,omitempty" toml:"readarr" xml:"readarr" yaml:"readarr,omitempty"`
Sonarr []*SonarrConfig `json:"sonarr,omitempty" toml:"sonarr" xml:"sonarr" yaml:"sonarr,omitempty"`
Folders []*FolderConfig `json:"folder,omitempty" toml:"folder" xml:"folder" yaml:"folder,omitempty"`
Webhook []*WebhookConfig `json:"webhook,omitempty" toml:"webhook" xml:"webhook" yaml:"webhook,omitempty"`
Cmdhook []*WebhookConfig `json:"cmdhook,omitempty" toml:"cmdhook" xml:"cmdhook" yaml:"cmdhook,omitempty"`
Folder FoldersConfig `json:"folders,omitempty" toml:"folders" xml:"folders" yaml:"folders,omitempty"` // undocumented.
Debug bool `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
Quiet bool `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
Activity bool `json:"activity" toml:"activity" xml:"activity" yaml:"activity"`
Parallel uint `json:"parallel" toml:"parallel" xml:"parallel" yaml:"parallel"`
ErrorStdErr bool `json:"errorStderr" toml:"error_stderr" xml:"error_stderr" yaml:"errorStderr"`
LogFile string `json:"logFile" toml:"log_file" xml:"log_file" yaml:"logFile"`
LogFiles int `json:"logFiles" toml:"log_files" xml:"log_files" yaml:"logFiles"`
LogFileMb int `json:"logFileMb" toml:"log_file_mb" xml:"log_file_mb" yaml:"logFileMb"`
MaxRetries uint `json:"maxRetries" toml:"max_retries" xml:"max_retries" yaml:"maxRetries"`
FileMode string `json:"fileMode" toml:"file_mode" xml:"file_mode" yaml:"fileMode"`
DirMode string `json:"dirMode" toml:"dir_mode" xml:"dir_mode" yaml:"dirMode"`
LogQueues cnfg.Duration `json:"logQueues" toml:"log_queues" xml:"log_queues" yaml:"logQueues"`
Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval" yaml:"interval"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
DeleteDelay cnfg.Duration `json:"deleteDelay" toml:"delete_delay" xml:"delete_delay" yaml:"deleteDelay"`
StartDelay cnfg.Duration `json:"startDelay" toml:"start_delay" xml:"start_delay" yaml:"startDelay"`
RetryDelay cnfg.Duration `json:"retryDelay" toml:"retry_delay" xml:"retry_delay" yaml:"retryDelay"`
KeepHistory uint `json:"keepHistory" toml:"keep_history" xml:"keep_history" yaml:"keepHistory"` // undocumented.
Passwords StringSlice `json:"passwords" toml:"passwords" xml:"password" yaml:"passwords"`
Webserver *WebServer `json:"webserver" toml:"webserver" xml:"webserver" yaml:"webserver"`
Lidarr []*LidarrConfig `json:"lidarr,omitempty" toml:"lidarr" xml:"lidarr" yaml:"lidarr,omitempty"`
Radarr []*RadarrConfig `json:"radarr,omitempty" toml:"radarr" xml:"radarr" yaml:"radarr,omitempty"`
Whisparr []*RadarrConfig `json:"whisparr,omitempty" toml:"whisparr" xml:"whisparr" yaml:"whisparr,omitempty"`
Readarr []*ReadarrConfig `json:"readarr,omitempty" toml:"readarr" xml:"readarr" yaml:"readarr,omitempty"`
Sonarr []*SonarrConfig `json:"sonarr,omitempty" toml:"sonarr" xml:"sonarr" yaml:"sonarr,omitempty"`
Folders []*FolderConfig `json:"folder,omitempty" toml:"folder" xml:"folder" yaml:"folder,omitempty"`
Webhook []*WebhookConfig `json:"webhook,omitempty" toml:"webhook" xml:"webhook" yaml:"webhook,omitempty"`
Cmdhook []*WebhookConfig `json:"cmdhook,omitempty" toml:"cmdhook" xml:"cmdhook" yaml:"cmdhook,omitempty"`
Folder FoldersConfig `json:"folders,omitempty" toml:"folders" xml:"folders" yaml:"folders,omitempty"` // undocumented.
}

type FoldersConfig struct {
Buffer uint `json:"buffer" toml:"buffer" xml:"buffer" yaml:"buffer"` // undocumented.
Buffer uint `json:"buffer" toml:"buffer" xml:"buffer" yaml:"buffer"` // undocumented.
Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval" yaml:"interval"` // undocumented.
}

Expand Down
26 changes: 13 additions & 13 deletions pkg/unpackerr/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const (
//
//nolint:lll
type FolderConfig struct {
DeleteOrig bool `json:"delete_original" toml:"delete_original" xml:"delete_original" yaml:"delete_original"`
DeleteFiles bool `json:"delete_files" toml:"delete_files" xml:"delete_files" yaml:"delete_files"`
DisableLog bool `json:"disable_log" toml:"disable_log" xml:"disable_log" yaml:"disable_log"`
MoveBack bool `json:"move_back" toml:"move_back" xml:"move_back" yaml:"move_back"`
DeleteAfter cnfg.Duration `json:"delete_after" toml:"delete_after" xml:"delete_after" yaml:"delete_after"`
ExtractPath string `json:"extract_path" toml:"extract_path" xml:"extract_path" yaml:"extract_path"`
ExtractISOs bool `json:"extract_isos" toml:"extract_isos" xml:"extract_isos" yaml:"extract_isos"`
DeleteOrig bool `json:"delete_original" toml:"delete_original" xml:"delete_original" yaml:"delete_original"`
DeleteFiles bool `json:"delete_files" toml:"delete_files" xml:"delete_files" yaml:"delete_files"`
DisableLog bool `json:"disable_log" toml:"disable_log" xml:"disable_log" yaml:"disable_log"`
MoveBack bool `json:"move_back" toml:"move_back" xml:"move_back" yaml:"move_back"`
DeleteAfter cnfg.Duration `json:"delete_after" toml:"delete_after" xml:"delete_after" yaml:"delete_after"`
ExtractPath string `json:"extract_path" toml:"extract_path" xml:"extract_path" yaml:"extract_path"`
ExtractISOs bool `json:"extract_isos" toml:"extract_isos" xml:"extract_isos" yaml:"extract_isos"`
DisableRecursion bool `json:"disableRecursion" toml:"disable_recursion" xml:"disable_recursion" yaml:"disableRecursion"`
Path string `json:"path" toml:"path" xml:"path" yaml:"path"`
Path string `json:"path" toml:"path" xml:"path" yaml:"path"`
}

// Folders holds all known (created) folders in all watch paths.
Expand All @@ -52,9 +52,9 @@ type Folders struct {

// Logs interface for folders.
type Logs interface {
Printf(msg string, v ...interface{})
Errorf(msg string, v ...interface{})
Debugf(msg string, v ...interface{})
Printf(msg string, v ...any)
Errorf(msg string, v ...any)
Debugf(msg string, v ...any)
}

// Folder is a "new" watched folder.
Expand Down Expand Up @@ -128,7 +128,7 @@ func (u *Unpackerr) PollFolders() {
go u.folders.watchFSNotify()
u.Printf("[Folder] Watching (fsnotify): %s", strings.Join(flist, ", "))

// Setting an interval of any value less than a millisecond
// Setting an interval of any value less than 5 milliseconds
// (except zero in docker) allows disabling the poller.
if u.Folder.Interval.Duration < minimumPollInterval {
return
Expand Down Expand Up @@ -548,7 +548,7 @@ func (u *Unpackerr) updateQueueStatus(data *newStatus, now time.Time, sendHook b
App: FolderString,
Status: QUEUED,
Updated: now,
IDs: map[string]interface{}{"title": data.Name}, // required or webhook may break.
IDs: map[string]any{"title": data.Name}, // required or webhook may break.
}

if sendHook {
Expand Down
16 changes: 8 additions & 8 deletions pkg/unpackerr/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ type Extract struct {
DeleteDelay time.Duration
DeleteOrig bool
Status ExtractStatus
IDs map[string]interface{}
IDs map[string]any
Resp *xtractr.Response
}

// Shared config items for all starr apps.
type StarrConfig struct {
Path string `json:"path" toml:"path" xml:"path" yaml:"path"`
Paths StringSlice `json:"paths" toml:"paths" xml:"paths" yaml:"paths"`
Protocols string `json:"protocols" toml:"protocols" xml:"protocols" yaml:"protocols"`
DeleteOrig bool `json:"delete_orig" toml:"delete_orig" xml:"delete_orig" yaml:"delete_orig"`
Path string `json:"path" toml:"path" xml:"path" yaml:"path"`
Paths StringSlice `json:"paths" toml:"paths" xml:"paths" yaml:"paths"`
Protocols string `json:"protocols" toml:"protocols" xml:"protocols" yaml:"protocols"`
DeleteOrig bool `json:"delete_orig" toml:"delete_orig" xml:"delete_orig" yaml:"delete_orig"`
DeleteDelay cnfg.Duration `json:"delete_delay" toml:"delete_delay" xml:"delete_delay" yaml:"delete_delay"`
Syncthing bool `json:"syncthing" toml:"syncthing" xml:"syncthing" yaml:"syncthing"`
ValidSSL bool `json:"valid_ssl" toml:"valid_ssl" xml:"valid_ssl" yaml:"valid_ssl"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
Syncthing bool `json:"syncthing" toml:"syncthing" xml:"syncthing" yaml:"syncthing"`
ValidSSL bool `json:"valid_ssl" toml:"valid_ssl" xml:"valid_ssl" yaml:"valid_ssl"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
starr.Config
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/unpackerr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (u *Unpackerr) checkLidarrQueue(now time.Time) {
DeleteDelay: server.DeleteDelay.Duration,
Syncthing: server.Syncthing,
Path: u.getDownloadPath(q.OutputPath, starr.Lidarr, q.Title, server.Paths),
IDs: map[string]interface{}{
IDs: map[string]any{
"title": q.Title,
"artistId": q.ArtistID,
"albumId": q.AlbumID,
Expand Down
6 changes: 3 additions & 3 deletions pkg/unpackerr/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ func (status ExtractStatus) String() string {
}

// Debugf writes Debug log lines... to stdout and/or a file.
func (l *Logger) Debugf(msg string, v ...interface{}) {
func (l *Logger) Debugf(msg string, v ...any) {
err := l.Debug.Output(callDepth, fmt.Sprintf(msg, v...))
if err != nil {
fmt.Println("Logger Error:", err) //nolint:forbidigo
}
}

// Printf writes log lines... to stdout and/or a file.
func (l *Logger) Printf(msg string, v ...interface{}) {
func (l *Logger) Printf(msg string, v ...any) {
err := l.Info.Output(callDepth, fmt.Sprintf(msg, v...))
if err != nil {
fmt.Println("Logger Error:", err) //nolint:forbidigo
}
}

// Errorf writes log errors... to stdout and/or a file.
func (l *Logger) Errorf(msg string, v ...interface{}) {
func (l *Logger) Errorf(msg string, v ...any) {
err := l.Error.Output(callDepth, fmt.Sprintf(msg, v...))
if err != nil {
fmt.Println("Logger Error:", err) //nolint:forbidigo
Expand Down
2 changes: 1 addition & 1 deletion pkg/unpackerr/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (u *Unpackerr) checkRadarrQueue(now time.Time) {
DeleteDelay: server.DeleteDelay.Duration,
Syncthing: server.Syncthing,
Path: u.getDownloadPath(q.OutputPath, starr.Radarr, q.Title, server.Paths),
IDs: map[string]interface{}{
IDs: map[string]any{
"downloadId": q.DownloadID,
"title": q.Title,
"movieId": q.MovieID,
Expand Down
2 changes: 1 addition & 1 deletion pkg/unpackerr/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (u *Unpackerr) checkReadarrQueue(now time.Time) {
DeleteDelay: server.DeleteDelay.Duration,
Syncthing: server.Syncthing,
Path: u.getDownloadPath(q.OutputPath, starr.Readarr, q.Title, server.Paths),
IDs: map[string]interface{}{
IDs: map[string]any{
"title": q.Title,
"authorId": q.AuthorID,
"bookId": q.BookID,
Expand Down
2 changes: 1 addition & 1 deletion pkg/unpackerr/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (u *Unpackerr) checkSonarrQueue(now time.Time) {
DeleteDelay: server.DeleteDelay.Duration,
Syncthing: server.Syncthing,
Path: u.getDownloadPath(q.OutputPath, starr.Sonarr, q.Title, server.Paths),
IDs: map[string]interface{}{
IDs: map[string]any{
"title": q.Title,
"downloadId": q.DownloadID,
"seriesId": q.SeriesID,
Expand Down
32 changes: 16 additions & 16 deletions pkg/unpackerr/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import (

// WebhookConfig defines the data to send webhooks to a server.
type WebhookConfig struct {
Name string `json:"name" toml:"name" xml:"name" yaml:"name"`
URL string `json:"url" toml:"url" xml:"url,omitempty" yaml:"url"`
Command string `json:"command" toml:"command" xml:"command,omitempty" yaml:"command"`
CType string `json:"contentType" toml:"content_type" xml:"content_type,omitempty" yaml:"contentType"`
Name string `json:"name" toml:"name" xml:"name" yaml:"name"`
URL string `json:"url" toml:"url" xml:"url,omitempty" yaml:"url"`
Command string `json:"command" toml:"command" xml:"command,omitempty" yaml:"command"`
CType string `json:"contentType" toml:"content_type" xml:"content_type,omitempty" yaml:"contentType"`
TmplPath string `json:"templatePath" toml:"template_path" xml:"template_path,omitempty" yaml:"templatePath"`
TempName string `json:"template" toml:"template" xml:"template,omitempty" yaml:"template"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
Shell bool `json:"shell" toml:"shell" xml:"shell" yaml:"shell"`
IgnoreSSL bool `json:"ignoreSsl" toml:"ignore_ssl" xml:"ignore_ssl,omitempty" yaml:"ignoreSsl"`
Silent bool `json:"silent" toml:"silent" xml:"silent" yaml:"silent"`
Events ExtractStatuses `json:"events" toml:"events" xml:"events" yaml:"events"`
Exclude StringSlice `json:"exclude" toml:"exclude" xml:"exclude" yaml:"exclude"`
Nickname string `json:"nickname" toml:"nickname" xml:"nickname,omitempty" yaml:"nickname"`
Token string `json:"token" toml:"token" xml:"token,omitempty" yaml:"token"`
Channel string `json:"channel" toml:"channel" xml:"channel,omitempty" yaml:"channel"`
TempName string `json:"template" toml:"template" xml:"template,omitempty" yaml:"template"`
Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
Shell bool `json:"shell" toml:"shell" xml:"shell" yaml:"shell"`
IgnoreSSL bool `json:"ignoreSsl" toml:"ignore_ssl" xml:"ignore_ssl,omitempty" yaml:"ignoreSsl"`
Silent bool `json:"silent" toml:"silent" xml:"silent" yaml:"silent"`
Events ExtractStatuses `json:"events" toml:"events" xml:"events" yaml:"events"`
Exclude StringSlice `json:"exclude" toml:"exclude" xml:"exclude" yaml:"exclude"`
Nickname string `json:"nickname" toml:"nickname" xml:"nickname,omitempty" yaml:"nickname"`
Token string `json:"token" toml:"token" xml:"token,omitempty" yaml:"token"`
Channel string `json:"channel" toml:"channel" xml:"channel,omitempty" yaml:"channel"`
client *http.Client
fails uint
posts uint
Expand Down Expand Up @@ -161,7 +161,7 @@ func (u *Unpackerr) sendWebhookWithLog(hook *WebhookConfig, payload *WebhookPayl
return
}

b := body.String() //nolint:ifshort
b := body.String()

if reply, err := hook.Send(&body); err != nil {
u.Debugf("Webhook Payload: %s", b)
Expand All @@ -173,7 +173,7 @@ func (u *Unpackerr) sendWebhookWithLog(hook *WebhookConfig, payload *WebhookPayl
}
}

// Send marshals an interface{} into json and POSTs it to a URL.
// Send marshals an any into json and POSTs it to a URL.
func (w *WebhookConfig) Send(body io.Reader) ([]byte, error) {
if w.URL == "" {
return nil, ErrWebhookNoURL
Expand Down
2 changes: 1 addition & 1 deletion pkg/unpackerr/webhook_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func samplePayload() *WebhookPayload {
return &WebhookPayload{
App: "Starr",
Path: "/this/is/a/path",
IDs: map[string]interface{}{
IDs: map[string]any{
"title": "Some Cool Title Name Here",
"downloadId": fmt.Sprintf("some-id-goes-here-%d", time.Now().Unix()),
"otherId": "another-id-here-like-imdb",
Expand Down
Loading

0 comments on commit d113a97

Please sign in to comment.