diff --git a/.github/workflows/codetests.yml b/.github/workflows/codetests.yml index cbe840b..acdd998 100644 --- a/.github/workflows/codetests.yml +++ b/.github/workflows/codetests.yml @@ -49,7 +49,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.9 + version: v2.11 # Runs golangci-lint on linux against linux and windows. golangci-linux: strategy: @@ -67,4 +67,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.9 + version: v2.11 diff --git a/.golangci.yml b/.golangci.yml index 7e0f7a8..d9909f6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,10 +9,6 @@ linters: - tagliatelle - noinlineerr - wsl - # fix these - - modernize - - perfsprint - - godoclint settings: wsl_v5: allow-first-in-block: true @@ -28,17 +24,9 @@ linters: - github.com/stretchr/testify - golift.io/starr - golang.org/x/net - ireturn: - allow: - - generic - - stdlib - - error exclusions: generated: lax presets: - - comments - - common-false-positives - - legacy - std-error-handling rules: - linters: @@ -51,10 +39,7 @@ linters: - lll - maintidx path: (.+)_test\.go - paths: - - third_party$ - - builtin$ - - examples$ + issues: max-issues-per-linter: 0 max-same-issues: 0 @@ -64,9 +49,3 @@ formatters: - gofmt - gofumpt - goimports - exclusions: - generated: lax - paths: - - third_party$ - - builtin$ - - examples$ diff --git a/debuglog/roundtripper.go b/debuglog/roundtripper.go index f7a302f..25df49c 100644 --- a/debuglog/roundtripper.go +++ b/debuglog/roundtripper.go @@ -17,7 +17,7 @@ import ( // Config is the input data for the logger. type Config struct { // This is where logs go. If not set they go to log.Printf. - Debugf func(string, ...interface{}) + Debugf func(string, ...any) // This can be used for byte counters, but is optional otherwise. Caller Caller // Any strings in this list are replaced with in the log output. @@ -156,18 +156,18 @@ func (f *fakeCloser) logRequest() (int, int) { } func (f *fakeCloser) headers() string { - var headers string + var headers strings.Builder for header, values := range f.Header { for _, value := range values { - headers += header + ": " + value + "\n" + headers.WriteString(header + ": " + value + "\n") } } - return headers + return headers.String() } -func (f *fakeCloser) redactLog(msg string, format ...interface{}) { +func (f *fakeCloser) redactLog(msg string, format ...any) { msg = fmt.Sprintf(msg, format...) for _, redact := range f.Redact { diff --git a/http.go b/http.go index 7b4fb05..437531d 100644 --- a/http.go +++ b/http.go @@ -127,7 +127,7 @@ func parseNon200(resp *http.Response) *ReqError { func closeResp(resp *http.Response) { if resp != nil && resp.Body != nil { _, _ = io.ReadAll(resp.Body) - resp.Body.Close() + _ = resp.Body.Close() } } @@ -148,7 +148,7 @@ func (c *Config) SetHeaders(req *http.Request) { req.Header.Set("Accept", "application/json") } - req.Header.Set("User-Agent", "go-starr: https://"+reflect.TypeOf(Config{}).PkgPath()) + req.Header.Set("User-Agent", "go-starr: https://"+reflect.TypeFor[Config]().PkgPath()) req.Header.Set("X-Api-Key", c.APIKey) } diff --git a/interface.go b/interface.go index 89377bc..e741f9f 100644 --- a/interface.go +++ b/interface.go @@ -29,10 +29,10 @@ type APIer interface { Put(ctx context.Context, req Request) (*http.Response, error) // Put request; Params should contain io.Reader. Delete(ctx context.Context, req Request) (*http.Response, error) // Delete request; Params are optional. // Normal data, unmarshals into provided interface. Use these because they close the response body. - GetInto(ctx context.Context, req Request, output interface{}) error // API GET Request. - PostInto(ctx context.Context, req Request, output interface{}) error // API POST Request. - PutInto(ctx context.Context, req Request, output interface{}) error // API PUT Request. - DeleteAny(ctx context.Context, req Request) error // API Delete request. + GetInto(ctx context.Context, req Request, output any) error // API GET Request. + PostInto(ctx context.Context, req Request, output any) error // API POST Request. + PutInto(ctx context.Context, req Request, output any) error // API PUT Request. + DeleteAny(ctx context.Context, req Request) error // API Delete request. } // Config must satisfy the APIer struct. @@ -116,21 +116,21 @@ func (c *Config) Delete(ctx context.Context, req Request) (*http.Response, error // GetInto performs an HTTP GET against an API path and // unmarshals the payload into the provided pointer interface. -func (c *Config) GetInto(ctx context.Context, req Request, output interface{}) error { +func (c *Config) GetInto(ctx context.Context, req Request, output any) error { resp, err := c.api(ctx, http.MethodGet, req) return decode(output, resp, err) } // PostInto performs an HTTP POST against an API path and // unmarshals the payload into the provided pointer interface. -func (c *Config) PostInto(ctx context.Context, req Request, output interface{}) error { +func (c *Config) PostInto(ctx context.Context, req Request, output any) error { resp, err := c.api(ctx, http.MethodPost, req) return decode(output, resp, err) } // PutInto performs an HTTP PUT against an API path and // unmarshals the payload into the provided pointer interface. -func (c *Config) PutInto(ctx context.Context, req Request, output interface{}) error { +func (c *Config) PutInto(ctx context.Context, req Request, output any) error { resp, err := c.api(ctx, http.MethodPut, req) return decode(output, resp, err) } @@ -144,7 +144,7 @@ func (c *Config) DeleteAny(ctx context.Context, req Request) error { } // decode is an extra procedure to check an error and decode the JSON resp.Body payload. -func decode(output interface{}, resp *http.Response, err error) error { +func decode(output any, resp *http.Response, err error) error { if err != nil { return err } else if output == nil { diff --git a/lidarr/album.go b/lidarr/album.go index 52f5569..3995832 100644 --- a/lidarr/album.go +++ b/lidarr/album.go @@ -25,7 +25,7 @@ type Album struct { ProfileID int64 `json:"profileId"` Duration int `json:"duration"` AlbumType string `json:"albumType"` - SecondaryTypes []interface{} `json:"secondaryTypes"` + SecondaryTypes []any `json:"secondaryTypes"` MediumCount int `json:"mediumCount"` Ratings *starr.Ratings `json:"ratings"` ReleaseDate time.Time `json:"releaseDate"` diff --git a/lidarr/artist.go b/lidarr/artist.go index bac9677..52ed28e 100644 --- a/lidarr/artist.go +++ b/lidarr/artist.go @@ -18,7 +18,7 @@ const bpArtist = APIver + "/artist" type Artist struct { ID int64 `json:"id"` Status string `json:"status,omitempty"` - LastInfoSync time.Time `json:"lastInfoSync,omitempty"` + LastInfoSync time.Time `json:"lastInfoSync,omitzero"` ArtistName string `json:"artistName,omitempty"` ForeignArtistID string `json:"foreignArtistId,omitempty"` TadbID int64 `json:"tadbId,omitempty"` @@ -36,7 +36,7 @@ type Artist struct { Images []*starr.Image `json:"images,omitempty"` Genres []string `json:"genres,omitempty"` Tags []int `json:"tags,omitempty"` - Added time.Time `json:"added,omitempty"` + Added time.Time `json:"added,omitzero"` Ratings *starr.Ratings `json:"ratings,omitempty"` Statistics *Statistics `json:"statistics,omitempty"` LastAlbum *Album `json:"lastAlbum,omitempty"` diff --git a/lidarr/blocklist.go b/lidarr/blocklist.go index 10c28a5..3b6000f 100644 --- a/lidarr/blocklist.go +++ b/lidarr/blocklist.go @@ -28,7 +28,7 @@ type BlockList struct { type BlockListRecord struct { Artist *Artist `json:"artist"` Quality *starr.Quality `json:"quality"` - CustomFormats []interface{} `json:"customFormats"` + CustomFormats []any `json:"customFormats"` AlbumIDs []int64 `json:"albumIds"` ID int64 `json:"id"` ArtistID int64 `json:"artistId"` diff --git a/lidarr/calendar_test.go b/lidarr/calendar_test.go index c3931fc..30c9a5d 100644 --- a/lidarr/calendar_test.go +++ b/lidarr/calendar_test.go @@ -93,7 +93,7 @@ var testCalendarStruct = lidarr.Album{ ArtistID: 163, ForeignAlbumID: "95b28969-3252-45a7-9e1b-b2d8f59eee45", ProfileID: 3, - SecondaryTypes: []interface{}{}, + SecondaryTypes: []any{}, Duration: 3897000, AlbumType: "Album", MediumCount: 1, diff --git a/lidarr/command.go b/lidarr/command.go index c58f267..f334322 100644 --- a/lidarr/command.go +++ b/lidarr/command.go @@ -54,10 +54,10 @@ type CommandResponse struct { Priority string `json:"priority"` Status string `json:"status"` Queued time.Time `json:"queued"` - Started time.Time `json:"started,omitempty"` - Ended time.Time `json:"ended,omitempty"` - StateChangeTime time.Time `json:"stateChangeTime,omitempty"` - LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"` + Started time.Time `json:"started,omitzero"` + Ended time.Time `json:"ended,omitzero"` + StateChangeTime time.Time `json:"stateChangeTime,omitzero"` + LastExecutionTime time.Time `json:"lastExecutionTime,omitzero"` Duration string `json:"duration,omitempty"` Trigger string `json:"trigger"` SendUpdatesToClient bool `json:"sendUpdatesToClient"` diff --git a/lidarr/command_test.go b/lidarr/command_test.go index 968d67b..6473931 100644 --- a/lidarr/command_test.go +++ b/lidarr/command_test.go @@ -51,7 +51,7 @@ func TestGetCommands(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }}, }, { @@ -117,7 +117,7 @@ func TestSendCommand(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }, }, { diff --git a/lidarr/downloadclient.go b/lidarr/downloadclient.go index 935c2e8..2d15002 100644 --- a/lidarr/downloadclient.go +++ b/lidarr/downloadclient.go @@ -114,7 +114,7 @@ func (l *Lidarr) TestDownloadClient(client *DownloadClientInput) error { // TestDownloadClientContext tests a download client. func (l *Lidarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(client); err != nil { diff --git a/lidarr/downloadclientconfig.go b/lidarr/downloadclientconfig.go index fd7c0a8..a2ed56a 100644 --- a/lidarr/downloadclientconfig.go +++ b/lidarr/downloadclientconfig.go @@ -26,7 +26,7 @@ func (l *Lidarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { return l.GetDownloadClientConfigContext(context.Background()) } -// GetDownloadClientConfig returns the download client config. +// GetDownloadClientConfigContext returns the download client config. func (l *Lidarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { var output DownloadClientConfig @@ -43,7 +43,7 @@ func (l *Lidarr) UpdateDownloadClientConfig(downloadClientConfig *DownloadClient return l.UpdateDownloadClientConfigContext(context.Background(), downloadClientConfig) } -// UpdateDownloadClientConfig update the single download client config. +// UpdateDownloadClientConfigContext update the single download client config. func (l *Lidarr) UpdateDownloadClientConfigContext(ctx context.Context, config *DownloadClientConfig, ) (*DownloadClientConfig, error) { diff --git a/lidarr/exclusions.go b/lidarr/exclusions.go index 260cfa0..9496492 100644 --- a/lidarr/exclusions.go +++ b/lidarr/exclusions.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "path" + "strings" "golift.io/starr" ) @@ -65,17 +66,17 @@ func (l *Lidarr) DeleteExclusions(ids []int64) error { // DeleteExclusionsContext removes exclusions from Lidarr. func (l *Lidarr) DeleteExclusionsContext(ctx context.Context, ids []int64) error { - var errs string + var errs strings.Builder for _, id := range ids { req := starr.Request{URI: path.Join(bpExclusions, starr.Str(id))} if err := l.DeleteAny(ctx, req); err != nil { - errs += fmt.Sprintf("api.Post(%s): %v ", &req, err) + fmt.Fprintf(&errs, "api.Post(%s): %v ", &req, err) } } - if errs != "" { - return fmt.Errorf("%w: %s", starr.ErrRequestError, errs) + if errs.Len() > 0 { + return fmt.Errorf("%w: %s", starr.ErrRequestError, errs.String()) } return nil diff --git a/lidarr/history.go b/lidarr/history.go index b1e57d3..fa6fc47 100644 --- a/lidarr/history.go +++ b/lidarr/history.go @@ -128,7 +128,7 @@ func (l *Lidarr) FailContext(ctx context.Context, historyID int64) error { return fmt.Errorf("%w: invalid history ID: %d", starr.ErrRequestError, historyID) } - var output interface{} + var output any req := starr.Request{ URI: path.Join(bpHistory, "failed"), diff --git a/lidarr/importlist.go b/lidarr/importlist.go index 3ea418f..9858f4a 100644 --- a/lidarr/importlist.go +++ b/lidarr/importlist.go @@ -81,7 +81,7 @@ func (l *Lidarr) GetImportList(importListID int64) (*ImportListOutput, error) { return l.GetImportListContext(context.Background(), importListID) } -// GetIndGetImportListContextexer returns a single import list. +// GetImportListContext returns a single import list. func (l *Lidarr) GetImportListContext(ctx context.Context, importListID int64) (*ImportListOutput, error) { var output ImportListOutput @@ -125,7 +125,7 @@ func (l *Lidarr) TestImportList(list *ImportListInput) error { // TestImportListContextt tests an import list. func (l *Lidarr) TestImportListContextt(ctx context.Context, list *ImportListInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(list); err != nil { diff --git a/lidarr/indexer.go b/lidarr/indexer.go index fe8d1bf..0010e82 100644 --- a/lidarr/indexer.go +++ b/lidarr/indexer.go @@ -76,7 +76,7 @@ func (l *Lidarr) TestIndexer(indexer *IndexerInput) error { // TestIndexerContext tests an indexer. func (l *Lidarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(indexer); err != nil { diff --git a/lidarr/lidarr.go b/lidarr/lidarr.go index 0d750a7..503242a 100644 --- a/lidarr/lidarr.go +++ b/lidarr/lidarr.go @@ -1,3 +1,4 @@ +// Package lidarr is the SDK client for the Lidarr API. package lidarr import ( diff --git a/lidarr/manualimport.go b/lidarr/manualimport.go index f7a2c15..3198801 100644 --- a/lidarr/manualimport.go +++ b/lidarr/manualimport.go @@ -160,7 +160,7 @@ func (l *Lidarr) ManualImportReprocess(manualimport *ManualImportInput) error { // ManualImportReprocessContext reprocesses a manual import (POST). func (l *Lidarr) ManualImportReprocessContext(ctx context.Context, manualimport *ManualImportInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(manualimport); err != nil { diff --git a/lidarr/mediamanagement.go b/lidarr/mediamanagement.go index e6411d3..70692d9 100644 --- a/lidarr/mediamanagement.go +++ b/lidarr/mediamanagement.go @@ -40,7 +40,7 @@ func (l *Lidarr) GetMediaManagement() (*MediaManagement, error) { return l.GetMediaManagementContext(context.Background()) } -// GetMediaManagement returns the Media Management. +// GetMediaManagementContext returns the Media Management. func (l *Lidarr) GetMediaManagementContext(ctx context.Context) (*MediaManagement, error) { var output MediaManagement diff --git a/lidarr/notification.go b/lidarr/notification.go index 1c27158..71836da 100644 --- a/lidarr/notification.go +++ b/lidarr/notification.go @@ -149,6 +149,7 @@ func (l *Lidarr) DeleteNotification(notificationID int64) error { return l.DeleteNotificationContext(context.Background(), notificationID) } +// DeleteNotificationContext removes a single notification. func (l *Lidarr) DeleteNotificationContext(ctx context.Context, notificationID int64) error { req := starr.Request{URI: path.Join(bpNotification, starr.Str(notificationID))} if err := l.DeleteAny(ctx, req); err != nil { diff --git a/lidarr/queue.go b/lidarr/queue.go index 9ac4450..67dce22 100644 --- a/lidarr/queue.go +++ b/lidarr/queue.go @@ -142,7 +142,7 @@ func (l *Lidarr) QueueGrabContext(ctx context.Context, ids ...int64) error { return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} if err := l.PostInto(ctx, req, &output); err != nil { diff --git a/lidarr/track.go b/lidarr/track.go index 8e8e0c5..2abe272 100644 --- a/lidarr/track.go +++ b/lidarr/track.go @@ -74,7 +74,7 @@ func (l *Lidarr) GetTracksByArtist(artistID int64) ([]*Track, error) { return l.GetTracksByArtistContext(context.Background(), artistID) } -// GetTracksByAlbumRelease gets track files using an artist ID. +// GetTracksByArtistContext gets track files using an artist ID. func (l *Lidarr) GetTracksByArtistContext(ctx context.Context, artistID int64) ([]*Track, error) { req := starr.Request{URI: bpTrack, Query: make(url.Values)} req.Query.Add("artistId", starr.Str(artistID)) diff --git a/paginate.go b/paginate.go index b14dc6d..bcb73fb 100644 --- a/paginate.go +++ b/paginate.go @@ -26,9 +26,9 @@ type PageReq struct { type Sorting string const ( - // SortAsc is the default, and sorts lists in ascending order. + // SortAscend is the default, and sorts lists in ascending order. SortAscend Sorting = "ascending" - // SortDesc flips the sort order to descending. + // SortDescend flips the sort order to descending. SortDescend Sorting = "descending" ) diff --git a/prowlarr/downloadclient.go b/prowlarr/downloadclient.go index 7d06cd8..7450a2c 100644 --- a/prowlarr/downloadclient.go +++ b/prowlarr/downloadclient.go @@ -110,7 +110,7 @@ func (p *Prowlarr) TestDownloadClient(client *DownloadClientInput) error { // TestDownloadClientContext tests a download client. func (p *Prowlarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(client); err != nil { diff --git a/prowlarr/indexer.go b/prowlarr/indexer.go index c3301e2..237cd68 100644 --- a/prowlarr/indexer.go +++ b/prowlarr/indexer.go @@ -103,7 +103,7 @@ func (p *Prowlarr) TestIndexer(indexer *IndexerInput) error { // TestIndexerContext tests an indexer. func (p *Prowlarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(indexer); err != nil { diff --git a/prowlarr/notification.go b/prowlarr/notification.go index d2e7e85..fde1ad8 100644 --- a/prowlarr/notification.go +++ b/prowlarr/notification.go @@ -146,6 +146,7 @@ func (p *Prowlarr) DeleteNotification(notificationID int64) error { return p.DeleteNotificationContext(context.Background(), notificationID) } +// DeleteNotificationContext removes a single notification. func (p *Prowlarr) DeleteNotificationContext(ctx context.Context, notificationID int64) error { req := starr.Request{URI: path.Join(bpNotification, starr.Str(notificationID))} if err := p.DeleteAny(ctx, req); err != nil { diff --git a/prowlarr/prowlarr.go b/prowlarr/prowlarr.go index ea6960f..9558b85 100644 --- a/prowlarr/prowlarr.go +++ b/prowlarr/prowlarr.go @@ -1,3 +1,4 @@ +// Package prowlarr is the SDK client for the Prowlarr API. package prowlarr import ( diff --git a/prowlarr/system.go b/prowlarr/system.go index a5dac3b..0a61565 100644 --- a/prowlarr/system.go +++ b/prowlarr/system.go @@ -69,7 +69,7 @@ func (p *Prowlarr) GetBackupFiles() ([]*starr.BackupFile, error) { return p.GetBackupFilesContext(context.Background()) } -// GetBackupFiles returns all available Prowlarr backup files. +// GetBackupFilesContext returns all available Prowlarr backup files. // Use GetBody to download a file using BackupFile.Path. func (p *Prowlarr) GetBackupFilesContext(ctx context.Context) ([]*starr.BackupFile, error) { var output []*starr.BackupFile diff --git a/prowlarr/tag.go b/prowlarr/tag.go index 184d19a..3e9694a 100644 --- a/prowlarr/tag.go +++ b/prowlarr/tag.go @@ -95,6 +95,7 @@ func (p *Prowlarr) DeleteTag(tagID int) error { return p.DeleteTagContext(context.Background(), tagID) } +// DeleteTagContext removes a single tag. func (p *Prowlarr) DeleteTagContext(ctx context.Context, tagID int) error { req := starr.Request{URI: path.Join(bpTag, starr.Str(tagID))} if err := p.DeleteAny(ctx, req); err != nil { diff --git a/radarr/command.go b/radarr/command.go index 8db0ddf..b6dfcdb 100644 --- a/radarr/command.go +++ b/radarr/command.go @@ -21,22 +21,22 @@ type CommandRequest struct { // CommandResponse comes from the /api/v3/command endpoint. type CommandResponse struct { - ID int64 `json:"id"` - Name string `json:"name"` - CommandName string `json:"commandName"` - Message string `json:"message,omitempty"` - Priority string `json:"priority"` - Status string `json:"status"` - Queued time.Time `json:"queued"` - Started time.Time `json:"started,omitempty"` - Ended time.Time `json:"ended,omitempty"` - StateChangeTime time.Time `json:"stateChangeTime,omitempty"` - LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"` - Duration string `json:"duration,omitempty"` - Trigger string `json:"trigger"` - SendUpdatesToClient bool `json:"sendUpdatesToClient"` - UpdateScheduledTask bool `json:"updateScheduledTask"` - Body map[string]interface{} `json:"body"` + ID int64 `json:"id"` + Name string `json:"name"` + CommandName string `json:"commandName"` + Message string `json:"message,omitempty"` + Priority string `json:"priority"` + Status string `json:"status"` + Queued time.Time `json:"queued"` + Started time.Time `json:"started,omitzero"` + Ended time.Time `json:"ended,omitzero"` + StateChangeTime time.Time `json:"stateChangeTime,omitzero"` + LastExecutionTime time.Time `json:"lastExecutionTime,omitzero"` + Duration string `json:"duration,omitzero"` + Trigger string `json:"trigger"` + SendUpdatesToClient bool `json:"sendUpdatesToClient"` + UpdateScheduledTask bool `json:"updateScheduledTask"` + Body map[string]any `json:"body"` } // GetCommands returns all available Radarr commands. diff --git a/radarr/command_test.go b/radarr/command_test.go index 84d9720..84e8e83 100644 --- a/radarr/command_test.go +++ b/radarr/command_test.go @@ -48,7 +48,7 @@ func TestGetCommands(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }}, }, { @@ -114,7 +114,7 @@ func TestSendCommand(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }, }, { diff --git a/radarr/downloadclient.go b/radarr/downloadclient.go index 73385ab..834a686 100644 --- a/radarr/downloadclient.go +++ b/radarr/downloadclient.go @@ -114,7 +114,7 @@ func (r *Radarr) TestDownloadClient(client *DownloadClientInput) error { // TestDownloadClientContext tests a download client. func (r *Radarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(client); err != nil { diff --git a/radarr/downloadclientconfig.go b/radarr/downloadclientconfig.go index 450261a..66170a5 100644 --- a/radarr/downloadclientconfig.go +++ b/radarr/downloadclientconfig.go @@ -27,7 +27,7 @@ func (r *Radarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { return r.GetDownloadClientConfigContext(context.Background()) } -// GetDownloadClientConfig returns the download client config. +// GetDownloadClientConfigContext returns the download client config. func (r *Radarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { var output DownloadClientConfig @@ -44,7 +44,7 @@ func (r *Radarr) UpdateDownloadClientConfig(downloadClientConfig *DownloadClient return r.UpdateDownloadClientConfigContext(context.Background(), downloadClientConfig) } -// UpdateDownloadClientConfig update the single download client config. +// UpdateDownloadClientConfigContext update the single download client config. func (r *Radarr) UpdateDownloadClientConfigContext(ctx context.Context, config *DownloadClientConfig, ) (*DownloadClientConfig, error) { diff --git a/radarr/exclusions.go b/radarr/exclusions.go index b13673e..5a4de62 100644 --- a/radarr/exclusions.go +++ b/radarr/exclusions.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "path" + "strings" "golift.io/starr" ) @@ -66,17 +67,17 @@ func (r *Radarr) DeleteExclusions(ids []int64) error { // DeleteExclusionsContext removes exclusions from Radarr. func (r *Radarr) DeleteExclusionsContext(ctx context.Context, ids []int64) error { - var errs string + var errs strings.Builder for _, id := range ids { req := starr.Request{URI: path.Join(bpExclusions, starr.Str(id))} if err := r.DeleteAny(ctx, req); err != nil { - errs += fmt.Sprintf("api.Post(%s): %v ", &req, err) + fmt.Fprintf(&errs, "api.Post(%s): %v ", &req, err) } } - if errs != "" { - return fmt.Errorf("%w: %s", starr.ErrRequestError, errs) + if errs.Len() > 0 { + return fmt.Errorf("%w: %s", starr.ErrRequestError, errs.String()) } return nil @@ -98,7 +99,7 @@ func (r *Radarr) AddExclusionsContext(ctx context.Context, exclusions []*Exclusi return fmt.Errorf("json.Marshal(%s): %w", bpExclusions, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: path.Join(bpExclusions, "bulk"), Body: &body} if err := r.PostInto(ctx, req, &output); err != nil { diff --git a/radarr/feed.go b/radarr/feed.go index a5d04e6..3e5752f 100644 --- a/radarr/feed.go +++ b/radarr/feed.go @@ -14,8 +14,10 @@ import ( // This is not an /api path. const bpFeed = "feed/" + APIver + "/calendar/radarr.ics" +// ReleaseType is the type of release, found in a calendar feed. type ReleaseType string +// ReleaseType constants. const ( ReleaseTypeCinema ReleaseType = "cinemaRelease" ReleaseTypeDigital ReleaseType = "digitalRelease" diff --git a/radarr/history.go b/radarr/history.go index ec2976c..cc5bfaa 100644 --- a/radarr/history.go +++ b/radarr/history.go @@ -129,7 +129,7 @@ func (r *Radarr) FailContext(ctx context.Context, historyID int64) error { return fmt.Errorf("%w: invalid history ID: %d", starr.ErrRequestError, historyID) } - var output interface{} // any ok + var output any // any ok // Strangely uses a POST without a payload. req := starr.Request{URI: path.Join(bpHistory, "failed", starr.Str(historyID))} diff --git a/radarr/importlist.go b/radarr/importlist.go index 18de1ac..38dc455 100644 --- a/radarr/importlist.go +++ b/radarr/importlist.go @@ -7,13 +7,14 @@ import ( "fmt" "net/url" "path" + "strings" "golift.io/starr" ) const bpImportList = APIver + "/importlist" -// ImportList represents the api/v3/importlist endpoint. +// ImportListInput represents the api/v3/importlist endpoint. type ImportListInput struct { EnableAuto bool `json:"enableAuto"` Enabled bool `json:"enabled"` @@ -34,7 +35,7 @@ type ImportListInput struct { Fields []*starr.FieldInput `json:"fields,omitempty"` } -// ImportList represents the api/v3/importlist endpoint. +// ImportListOutput represents the api/v3/importlist endpoint. type ImportListOutput struct { EnableAuto bool `json:"enableAuto"` Enabled bool `json:"enabled"` @@ -104,17 +105,17 @@ func (r *Radarr) DeleteImportList(ids []int64) error { // DeleteImportListContext removes an import list from Radarr. func (r *Radarr) DeleteImportListContext(ctx context.Context, ids []int64) error { - var errs string + var errs strings.Builder for _, id := range ids { req := starr.Request{URI: path.Join(bpImportList, starr.Str(id))} if err := r.DeleteAny(ctx, req); err != nil { - errs += fmt.Errorf("api.Delete(%s): %w", &req, err).Error() + " " + errs.WriteString(fmt.Errorf("api.Delete(%s): %w", &req, err).Error() + " ") } } - if errs != "" { - return fmt.Errorf("%w: %s", starr.ErrRequestError, errs) + if errs.Len() > 0 { + return fmt.Errorf("%w: %s", starr.ErrRequestError, errs.String()) } return nil @@ -127,7 +128,7 @@ func (r *Radarr) TestImportList(list *ImportListInput) error { // TestImportListContextt tests an import list. func (r *Radarr) TestImportListContextt(ctx context.Context, list *ImportListInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(list); err != nil { diff --git a/radarr/indexer.go b/radarr/indexer.go index 24a60a3..5ba20ea 100644 --- a/radarr/indexer.go +++ b/radarr/indexer.go @@ -90,7 +90,7 @@ func (r *Radarr) TestIndexer(indexer *IndexerInput) error { // TestIndexerContext tests an indexer. func (r *Radarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(indexer); err != nil { diff --git a/radarr/manualimport.go b/radarr/manualimport.go index b7e9d4a..55d5586 100644 --- a/radarr/manualimport.go +++ b/radarr/manualimport.go @@ -91,7 +91,7 @@ func (r *Radarr) ManualImportReprocess(manualimport *ManualImportInput) error { // ManualImportReprocessContext reprocesses a manual import (POST). func (r *Radarr) ManualImportReprocessContext(ctx context.Context, manualimport *ManualImportInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(manualimport); err != nil { diff --git a/radarr/mediamanagement.go b/radarr/mediamanagement.go index 16842d4..059e2c8 100644 --- a/radarr/mediamanagement.go +++ b/radarr/mediamanagement.go @@ -43,7 +43,7 @@ func (r *Radarr) GetMediaManagement() (*MediaManagement, error) { return r.GetMediaManagementContext(context.Background()) } -// GetMediaManagement returns the media management. +// GetMediaManagementContext returns the media management. func (r *Radarr) GetMediaManagementContext(ctx context.Context) (*MediaManagement, error) { var output MediaManagement diff --git a/radarr/movie.go b/radarr/movie.go index cc98b6b..32c15b2 100644 --- a/radarr/movie.go +++ b/radarr/movie.go @@ -29,10 +29,10 @@ type Movie struct { SizeOnDisk int64 `json:"sizeOnDisk,omitempty"` Status string `json:"status,omitempty"` Overview string `json:"overview,omitempty"` - InCinemas time.Time `json:"inCinemas,omitempty"` - PhysicalRelease time.Time `json:"physicalRelease,omitempty"` - DigitalRelease time.Time `json:"digitalRelease,omitempty"` - ReleaseDate time.Time `json:"releaseDate,omitempty"` + InCinemas time.Time `json:"inCinemas,omitzero"` + PhysicalRelease time.Time `json:"physicalRelease,omitzero"` + DigitalRelease time.Time `json:"digitalRelease,omitzero"` + ReleaseDate time.Time `json:"releaseDate,omitzero"` Images []*starr.Image `json:"images,omitempty"` Website string `json:"website,omitempty"` Year int `json:"year,omitempty"` @@ -46,7 +46,7 @@ type Movie struct { Certification string `json:"certification,omitempty"` Genres []string `json:"genres,omitempty"` Tags []int `json:"tags,omitempty"` - Added time.Time `json:"added,omitempty"` + Added time.Time `json:"added,omitzero"` Ratings starr.OpenRatings `json:"ratings,omitempty"` MovieFile *MovieFile `json:"movieFile,omitempty"` Collection *Collection `json:"collection,omitempty"` diff --git a/radarr/moviefile.go b/radarr/moviefile.go index feb9cda..84a41dd 100644 --- a/radarr/moviefile.go +++ b/radarr/moviefile.go @@ -131,12 +131,12 @@ func (r *Radarr) UpdateMovieFileContext(ctx context.Context, movieFile *MovieFil return output, nil } -// DeleteMovieFile deletes movie files by their IDs. +// DeleteMovieFiles deletes movie files by their IDs. func (r *Radarr) DeleteMovieFiles(movieFileIDs ...int64) error { return r.DeleteMovieFilesContext(context.Background(), movieFileIDs...) } -// DeleteMovieFileContext deletes movie files by their IDs. +// DeleteMovieFilesContext deletes movie files by their IDs. func (r *Radarr) DeleteMovieFilesContext(ctx context.Context, movieFileIDs ...int64) error { postData := struct { T []int64 `json:"movieFileIds"` diff --git a/radarr/notification.go b/radarr/notification.go index c13ae90..85c3825 100644 --- a/radarr/notification.go +++ b/radarr/notification.go @@ -152,6 +152,7 @@ func (r *Radarr) DeleteNotification(notificationID int64) error { return r.DeleteNotificationContext(context.Background(), notificationID) } +// DeleteNotificationContext removes a single notification. func (r *Radarr) DeleteNotificationContext(ctx context.Context, notificationID int64) error { req := starr.Request{URI: path.Join(bpNotification, starr.Str(notificationID))} if err := r.DeleteAny(ctx, req); err != nil { diff --git a/radarr/queue.go b/radarr/queue.go index 2f96295..f4d1c0f 100644 --- a/radarr/queue.go +++ b/radarr/queue.go @@ -93,7 +93,7 @@ func (r *Radarr) GetQueuePage(params *starr.PageReq) (*Queue, error) { return r.GetQueuePageContext(context.Background(), params) } -// GetQueuePage returns a single page from the Radarr Queue. +// GetQueuePageContext returns a single page from the Radarr Queue. // The page size and number is configurable with the input request parameters. func (r *Radarr) GetQueuePageContext(ctx context.Context, params *starr.PageReq) (*Queue, error) { var output Queue @@ -142,7 +142,7 @@ func (r *Radarr) QueueGrabContext(ctx context.Context, ids ...int64) error { return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} if err := r.PostInto(ctx, req, &output); err != nil { diff --git a/radarr/radarr.go b/radarr/radarr.go index 92b9f54..e6b1855 100644 --- a/radarr/radarr.go +++ b/radarr/radarr.go @@ -1,3 +1,4 @@ +// Package radarr is the SDK client for the Radarr API. package radarr import ( diff --git a/radarr/restriction.go b/radarr/restriction.go index 3d15fbe..1e853ea 100644 --- a/radarr/restriction.go +++ b/radarr/restriction.go @@ -42,7 +42,7 @@ func (r *Radarr) GetRestriction(restrictionID int64) (*Restriction, error) { return r.GetRestrictionContext(context.Background(), restrictionID) } -// GetIndGetRestrictionContextexer returns a single restriction. +// GetRestrictionContext returns a single restriction. func (r *Radarr) GetRestrictionContext(ctx context.Context, restrictionID int64) (*Restriction, error) { var output Restriction diff --git a/readarr/author.go b/readarr/author.go index 9201b32..afeb629 100644 --- a/readarr/author.go +++ b/readarr/author.go @@ -31,7 +31,7 @@ type Author struct { CleanName string `json:"cleanName,omitempty"` SortName string `json:"sortName,omitempty"` Tags []int `json:"tags,omitempty"` - Added time.Time `json:"added,omitempty"` + Added time.Time `json:"added,omitzero"` Ratings *starr.Ratings `json:"ratings,omitempty"` Statistics *Statistics `json:"statistics,omitempty"` LastBook *AuthorBook `json:"lastBook,omitempty"` diff --git a/readarr/blocklist.go b/readarr/blocklist.go index 9ce2bbe..f15d886 100644 --- a/readarr/blocklist.go +++ b/readarr/blocklist.go @@ -28,7 +28,7 @@ type BlockList struct { type BlockListRecord struct { Author *Author `json:"author"` Quality *starr.Quality `json:"quality"` - CustomFormats []interface{} `json:"customFormats"` + CustomFormats []any `json:"customFormats"` BookIDs []int64 `json:"bookIds"` ID int64 `json:"id"` AuthorID int64 `json:"authorId"` diff --git a/readarr/book.go b/readarr/book.go index 00f3d2e..38ce642 100644 --- a/readarr/book.go +++ b/readarr/book.go @@ -165,7 +165,7 @@ func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Boo } req.Query.Add("moveFiles", starr.Str(moveFiles)) - var output interface{} // do not know what this looks like. + var output any // do not know what this looks like. if err := r.PutInto(ctx, req, &output); err != nil { return fmt.Errorf("api.Put(%s): %w", &req, err) diff --git a/readarr/bookfile.go b/readarr/bookfile.go index 574ee30..094195a 100644 --- a/readarr/bookfile.go +++ b/readarr/bookfile.go @@ -20,7 +20,7 @@ type BookFile struct { BookID int64 `json:"bookId"` Path string `json:"path"` Size int `json:"size,omitempty"` - DateAdded time.Time `json:"dateAdded,omitempty"` + DateAdded time.Time `json:"dateAdded,omitzero"` Quality *starr.Quality `json:"quality"` QualityWeight int `json:"qualityWeight,omitempty"` QualityCutoffNotMet bool `json:"qualityCutoffNotMet"` diff --git a/readarr/command.go b/readarr/command.go index e2b9d0d..1f99454 100644 --- a/readarr/command.go +++ b/readarr/command.go @@ -22,22 +22,22 @@ type CommandRequest struct { // CommandResponse comes from the /api/v1/command endpoint. type CommandResponse struct { - ID int64 `json:"id"` - Name string `json:"name"` - CommandName string `json:"commandName"` - Message string `json:"message,omitempty"` - Priority string `json:"priority"` - Status string `json:"status"` - Queued time.Time `json:"queued"` - Started time.Time `json:"started,omitempty"` - Ended time.Time `json:"ended,omitempty"` - StateChangeTime time.Time `json:"stateChangeTime,omitempty"` - LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"` - Duration string `json:"duration,omitempty"` - Trigger string `json:"trigger"` - SendUpdatesToClient bool `json:"sendUpdatesToClient"` - UpdateScheduledTask bool `json:"updateScheduledTask"` - Body map[string]interface{} `json:"body"` + ID int64 `json:"id"` + Name string `json:"name"` + CommandName string `json:"commandName"` + Message string `json:"message,omitempty"` + Priority string `json:"priority"` + Status string `json:"status"` + Queued time.Time `json:"queued"` + Started time.Time `json:"started,omitzero"` + Ended time.Time `json:"ended,omitzero"` + StateChangeTime time.Time `json:"stateChangeTime,omitzero"` + LastExecutionTime time.Time `json:"lastExecutionTime,omitzero"` + Duration string `json:"duration,omitempty"` + Trigger string `json:"trigger"` + SendUpdatesToClient bool `json:"sendUpdatesToClient"` + UpdateScheduledTask bool `json:"updateScheduledTask"` + Body map[string]any `json:"body"` } // GetCommands returns all available Readarr commands. diff --git a/readarr/command_test.go b/readarr/command_test.go index 46a0c25..b440ab7 100644 --- a/readarr/command_test.go +++ b/readarr/command_test.go @@ -48,7 +48,7 @@ func TestGetCommands(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }}, }, { @@ -115,7 +115,7 @@ func TestSendCommand(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }, }, { diff --git a/readarr/downloadclient.go b/readarr/downloadclient.go index 3c0a67b..f44783c 100644 --- a/readarr/downloadclient.go +++ b/readarr/downloadclient.go @@ -111,7 +111,7 @@ func (r *Readarr) TestDownloadClient(client *DownloadClientInput) error { // TestDownloadClientContext tests a download client. func (r *Readarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(client); err != nil { diff --git a/readarr/downloadclientconfig.go b/readarr/downloadclientconfig.go index 2d6f6fc..b101b77 100644 --- a/readarr/downloadclientconfig.go +++ b/readarr/downloadclientconfig.go @@ -28,7 +28,7 @@ func (r *Readarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { return r.GetDownloadClientConfigContext(context.Background()) } -// GetDownloadClientConfig returns the download client config. +// GetDownloadClientConfigContext returns the download client config. func (r *Readarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { var output DownloadClientConfig @@ -45,7 +45,7 @@ func (r *Readarr) UpdateDownloadClientConfig(downloadConfig *DownloadClientConfi return r.UpdateDownloadClientConfigContext(context.Background(), downloadConfig) } -// UpdateDownloadClientConfig update the single download client config. +// UpdateDownloadClientConfigContext update the single download client config. func (r *Readarr) UpdateDownloadClientConfigContext(ctx context.Context, config *DownloadClientConfig, ) (*DownloadClientConfig, error) { diff --git a/readarr/exclusions.go b/readarr/exclusions.go index 8a7cb29..6f769ab 100644 --- a/readarr/exclusions.go +++ b/readarr/exclusions.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "path" + "strings" "golift.io/starr" ) @@ -65,17 +66,17 @@ func (r *Readarr) DeleteExclusions(ids []int64) error { // DeleteExclusionsContext removes exclusions from Readarr. func (r *Readarr) DeleteExclusionsContext(ctx context.Context, ids []int64) error { - var errs string + var errs strings.Builder for _, id := range ids { req := starr.Request{URI: path.Join(bpExclusions, starr.Str(id))} if err := r.DeleteAny(ctx, req); err != nil { - errs += fmt.Sprintf("api.Post(%s): %v ", &req, err) + fmt.Fprintf(&errs, "api.Post(%s): %v ", &req, err) } } - if errs != "" { - return fmt.Errorf("%w: %s", starr.ErrRequestError, errs) + if errs.Len() > 0 { + return fmt.Errorf("%w: %s", starr.ErrRequestError, errs.String()) } return nil diff --git a/readarr/history.go b/readarr/history.go index f68d51c..1b1aa69 100644 --- a/readarr/history.go +++ b/readarr/history.go @@ -128,7 +128,7 @@ func (r *Readarr) FailContext(ctx context.Context, historyID int64) error { return fmt.Errorf("%w: invalid history ID: %d", starr.ErrRequestError, historyID) } - var output interface{} + var output any req := starr.Request{ URI: path.Join(bpHistory, "failed"), diff --git a/readarr/importlist.go b/readarr/importlist.go index 0099c59..7e785c8 100644 --- a/readarr/importlist.go +++ b/readarr/importlist.go @@ -77,7 +77,7 @@ func (r *Readarr) GetImportList(importListID int64) (*ImportListOutput, error) { return r.GetImportListContext(context.Background(), importListID) } -// GetIndGetImportListContextexer returns a single import list. +// GetImportListContext returns a single import list. func (r *Readarr) GetImportListContext(ctx context.Context, importListID int64) (*ImportListOutput, error) { var output ImportListOutput @@ -121,7 +121,7 @@ func (r *Readarr) TestImportList(list *ImportListInput) error { // TestImportListContextt tests an import list. func (r *Readarr) TestImportListContextt(ctx context.Context, list *ImportListInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(list); err != nil { diff --git a/readarr/indexer.go b/readarr/indexer.go index 532a290..9982338 100644 --- a/readarr/indexer.go +++ b/readarr/indexer.go @@ -69,7 +69,7 @@ func (r *Readarr) GetIndexer(indexerID int64) (*IndexerOutput, error) { return r.GetIndexerContext(context.Background(), indexerID) } -// GetIndGetIndexerContextexer returns a single indexer. +// GetIndexerContext returns a single indexer. func (r *Readarr) GetIndexerContext(ctx context.Context, indexerID int64) (*IndexerOutput, error) { var output IndexerOutput @@ -88,7 +88,7 @@ func (r *Readarr) TestIndexer(indexer *IndexerInput) error { // TestIndexerContext tests an indexer. func (r *Readarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(indexer); err != nil { diff --git a/readarr/manualimport.go b/readarr/manualimport.go index a6d8685..40e85b8 100644 --- a/readarr/manualimport.go +++ b/readarr/manualimport.go @@ -95,7 +95,7 @@ func (r *Readarr) ManualImportReprocess(manualimport *ManualImportInput) error { // ManualImportReprocessContext reprocesses a manual import (POST). func (r *Readarr) ManualImportReprocessContext(ctx context.Context, manualimport *ManualImportInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(manualimport); err != nil { diff --git a/readarr/mediamanagement.go b/readarr/mediamanagement.go index e2f75af..46bc20b 100644 --- a/readarr/mediamanagement.go +++ b/readarr/mediamanagement.go @@ -40,7 +40,7 @@ func (r *Readarr) GetMediaManagement() (*MediaManagement, error) { return r.GetMediaManagementContext(context.Background()) } -// GetMediaManagement returns the media management. +// GetMediaManagementContext returns the media management. func (r *Readarr) GetMediaManagementContext(ctx context.Context) (*MediaManagement, error) { var output MediaManagement diff --git a/readarr/notification.go b/readarr/notification.go index 109c5f2..037e157 100644 --- a/readarr/notification.go +++ b/readarr/notification.go @@ -161,6 +161,7 @@ func (r *Readarr) DeleteNotification(notificationID int64) error { return r.DeleteNotificationContext(context.Background(), notificationID) } +// DeleteNotificationContext removes a single notification. func (r *Readarr) DeleteNotificationContext(ctx context.Context, notificationID int64) error { req := starr.Request{URI: path.Join(bpNotification, starr.Str(notificationID))} if err := r.DeleteAny(ctx, req); err != nil { diff --git a/readarr/queue.go b/readarr/queue.go index 1f838b0..f2c6651 100644 --- a/readarr/queue.go +++ b/readarr/queue.go @@ -144,7 +144,7 @@ func (r *Readarr) QueueGrabContext(ctx context.Context, ids ...int64) error { return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} if err := r.PostInto(ctx, req, &output); err != nil { diff --git a/readarr/readarr.go b/readarr/readarr.go index 74eccb9..cbadd23 100644 --- a/readarr/readarr.go +++ b/readarr/readarr.go @@ -1,3 +1,4 @@ +// Package readarr is the SDK client for the Readarr API. package readarr import ( diff --git a/shared.go b/shared.go index 9fad051..e6574bb 100644 --- a/shared.go +++ b/shared.go @@ -116,14 +116,14 @@ type FieldOutput struct { SelectOptionsProviderAction string `json:"selectOptionsProviderAction,omitempty"` Type string `json:"type,omitempty"` Privacy string `json:"privacy"` - Value interface{} `json:"value,omitempty"` + Value any `json:"value,omitempty"` SelectOptions []*SelectOption `json:"selectOptions,omitempty"` } // FieldInput is generic Name/Value struct applied to a few places. type FieldInput struct { - Name string `json:"name"` - Value interface{} `json:"value,omitempty"` + Name string `json:"name"` + Value any `json:"value,omitempty"` } // SelectOption is part of Field. @@ -227,6 +227,8 @@ func (d *PlayTime) UnmarshalJSON(b []byte) error { return nil } +// MarshalJSON marshals the PlayTime to JSON. +// //nolint:wrapcheck,mnd // no value added, seconds per hour, etc. func (d *PlayTime) MarshalJSON() ([]byte, error) { s := d.Original diff --git a/sonarr/command.go b/sonarr/command.go index 84b8439..2c74a76 100644 --- a/sonarr/command.go +++ b/sonarr/command.go @@ -27,22 +27,22 @@ type CommandRequest struct { // CommandResponse comes from the /api/v3/command endpoint. type CommandResponse struct { - ID int64 `json:"id"` - Name string `json:"name"` - CommandName string `json:"commandName"` - Message string `json:"message,omitempty"` - Priority string `json:"priority"` - Status string `json:"status"` - Queued time.Time `json:"queued"` - Started time.Time `json:"started,omitempty"` - Ended time.Time `json:"ended,omitempty"` - StateChangeTime time.Time `json:"stateChangeTime,omitempty"` - LastExecutionTime time.Time `json:"lastExecutionTime,omitempty"` - Duration string `json:"duration,omitempty"` - Trigger string `json:"trigger"` - SendUpdatesToClient bool `json:"sendUpdatesToClient"` - UpdateScheduledTask bool `json:"updateScheduledTask"` - Body map[string]interface{} `json:"body"` + ID int64 `json:"id"` + Name string `json:"name"` + CommandName string `json:"commandName"` + Message string `json:"message,omitempty"` + Priority string `json:"priority"` + Status string `json:"status"` + Queued time.Time `json:"queued"` + Started time.Time `json:"started,omitzero"` + Ended time.Time `json:"ended,omitzero"` + StateChangeTime time.Time `json:"stateChangeTime,omitzero"` + LastExecutionTime time.Time `json:"lastExecutionTime,omitzero"` + Duration string `json:"duration,omitempty"` + Trigger string `json:"trigger"` + SendUpdatesToClient bool `json:"sendUpdatesToClient"` + UpdateScheduledTask bool `json:"updateScheduledTask"` + Body map[string]any `json:"body"` } // GetCommands returns all available Sonarr commands. @@ -51,7 +51,7 @@ func (s *Sonarr) GetCommands() ([]*CommandResponse, error) { return s.GetCommandsContext(context.Background()) } -// GetCommands returns all available Sonarr commands. +// GetCommandsContext returns all available Sonarr commands. // These can be used with SendCommand. func (s *Sonarr) GetCommandsContext(ctx context.Context) ([]*CommandResponse, error) { var output []*CommandResponse diff --git a/sonarr/command_test.go b/sonarr/command_test.go index 9fb0e35..04d4f00 100644 --- a/sonarr/command_test.go +++ b/sonarr/command_test.go @@ -49,7 +49,7 @@ func TestGetCommands(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }}, }, { @@ -116,7 +116,7 @@ func TestSendCommand(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }, }, { @@ -185,7 +185,7 @@ func TestGetCommandStatus(t *testing.T) { Trigger: "someTrigger", SendUpdatesToClient: true, UpdateScheduledTask: true, - Body: map[string]interface{}{"mapstring": "mapinterface"}, + Body: map[string]any{"mapstring": "mapinterface"}, }, }, { diff --git a/sonarr/downloadclient.go b/sonarr/downloadclient.go index 4206e9b..4c8d0cd 100644 --- a/sonarr/downloadclient.go +++ b/sonarr/downloadclient.go @@ -114,7 +114,7 @@ func (s *Sonarr) TestDownloadClient(client *DownloadClientInput) error { // TestDownloadClientContext tests a download client. func (s *Sonarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(client); err != nil { diff --git a/sonarr/downloadclientconfig.go b/sonarr/downloadclientconfig.go index 5d34789..fd75d29 100644 --- a/sonarr/downloadclientconfig.go +++ b/sonarr/downloadclientconfig.go @@ -26,7 +26,7 @@ func (s *Sonarr) GetDownloadClientConfig() (*DownloadClientConfig, error) { return s.GetDownloadClientConfigContext(context.Background()) } -// GetDownloadClientConfig returns the download client config. +// GetDownloadClientConfigContext returns the download client config. func (s *Sonarr) GetDownloadClientConfigContext(ctx context.Context) (*DownloadClientConfig, error) { var output DownloadClientConfig @@ -43,7 +43,7 @@ func (s *Sonarr) UpdateDownloadClientConfig(downloadClientConfig *DownloadClient return s.UpdateDownloadClientConfigContext(context.Background(), downloadClientConfig) } -// UpdateDownloadClientConfig update the single download client config. +// UpdateDownloadClientConfigContext update the single download client config. func (s *Sonarr) UpdateDownloadClientConfigContext(ctx context.Context, config *DownloadClientConfig, ) (*DownloadClientConfig, error) { diff --git a/sonarr/episodefile.go b/sonarr/episodefile.go index 63f95c8..a731414 100644 --- a/sonarr/episodefile.go +++ b/sonarr/episodefile.go @@ -70,7 +70,7 @@ func (s *Sonarr) GetEpisodeFilesContext(ctx context.Context, episodeFileIDs ...i return output, nil } -// GetSeriesEpisodeFile returns information about all episode files in a series. +// GetSeriesEpisodeFiles returns information about all episode files in a series. func (s *Sonarr) GetSeriesEpisodeFiles(seriesID int64) ([]*EpisodeFile, error) { return s.GetSeriesEpisodeFilesContext(context.Background(), seriesID) } @@ -89,7 +89,7 @@ func (s *Sonarr) GetSeriesEpisodeFilesContext(ctx context.Context, seriesID int6 return output, nil } -// UpdateEpisodeFile updates an episode file's quality. Use GetQualityProfiles() to find the available IDs. +// UpdateEpisodeFileQuality updates an episode file's quality. Use GetQualityProfiles() to find the available IDs. func (s *Sonarr) UpdateEpisodeFileQuality(episodeFileID, qualityID int64) (*EpisodeFile, error) { return s.UpdateEpisodeFileQualityContext(context.Background(), episodeFileID, qualityID) } diff --git a/sonarr/exclusions.go b/sonarr/exclusions.go index cb3d64a..9ada063 100644 --- a/sonarr/exclusions.go +++ b/sonarr/exclusions.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "path" + "strings" "golift.io/starr" ) @@ -65,17 +66,17 @@ func (s *Sonarr) DeleteExclusions(ids []int64) error { // DeleteExclusionsContext removes exclusions from Sonarr. func (s *Sonarr) DeleteExclusionsContext(ctx context.Context, ids []int64) error { - var errs string + var errs strings.Builder for _, id := range ids { req := starr.Request{URI: path.Join(bpExclusions, starr.Str(id))} if err := s.DeleteAny(ctx, req); err != nil { - errs += fmt.Sprintf("api.Post(%s): %v ", &req, err) + fmt.Fprintf(&errs, "api.Post(%s): %v ", &req, err) } } - if errs != "" { - return fmt.Errorf("%w: %s", starr.ErrRequestError, errs) + if errs.Len() > 0 { + return fmt.Errorf("%w: %s", starr.ErrRequestError, errs.String()) } return nil diff --git a/sonarr/history.go b/sonarr/history.go index 6e066ea..2ce486a 100644 --- a/sonarr/history.go +++ b/sonarr/history.go @@ -131,7 +131,7 @@ func (s *Sonarr) FailContext(ctx context.Context, historyID int64) error { return fmt.Errorf("%w: invalid history ID: %d", starr.ErrRequestError, historyID) } - var output interface{} // any ok + var output any // any ok // Strangely uses a POST without a payload. req := starr.Request{URI: path.Join(bpHistory, "failed", starr.Str(historyID))} diff --git a/sonarr/importlist.go b/sonarr/importlist.go index f3b2b54..60a59d7 100644 --- a/sonarr/importlist.go +++ b/sonarr/importlist.go @@ -77,7 +77,7 @@ func (s *Sonarr) GetImportList(importListID int64) (*ImportListOutput, error) { return s.GetImportListContext(context.Background(), importListID) } -// GetIndGetImportListContextexer returns a single import list. +// GetImportListContext returns a single import list. func (s *Sonarr) GetImportListContext(ctx context.Context, importListID int64) (*ImportListOutput, error) { var output ImportListOutput @@ -121,7 +121,7 @@ func (s *Sonarr) TestImportList(list *ImportListInput) error { // TestImportListContextt tests an import list. func (s *Sonarr) TestImportListContextt(ctx context.Context, list *ImportListInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(list); err != nil { diff --git a/sonarr/indexer.go b/sonarr/indexer.go index 1138224..4b42da7 100644 --- a/sonarr/indexer.go +++ b/sonarr/indexer.go @@ -90,7 +90,7 @@ func (s *Sonarr) TestIndexer(indexer *IndexerInput) error { // TestIndexerContext tests an indexer. func (s *Sonarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error { - var output interface{} // any ok + var output any // any ok var body bytes.Buffer if err := json.NewEncoder(&body).Encode(indexer); err != nil { diff --git a/sonarr/manualimport.go b/sonarr/manualimport.go index e2cfbfd..2c0d49d 100644 --- a/sonarr/manualimport.go +++ b/sonarr/manualimport.go @@ -98,7 +98,7 @@ func (s *Sonarr) ManualImportReprocess(manualimport *ManualImportInput) error { // ManualImportReprocessContext reprocesses a manual import (POST). func (s *Sonarr) ManualImportReprocessContext(ctx context.Context, manualimport *ManualImportInput) error { - var output interface{} + var output any var body bytes.Buffer if err := json.NewEncoder(&body).Encode(manualimport); err != nil { diff --git a/sonarr/mediamanagement.go b/sonarr/mediamanagement.go index a561cb2..1d528f5 100644 --- a/sonarr/mediamanagement.go +++ b/sonarr/mediamanagement.go @@ -42,7 +42,7 @@ func (s *Sonarr) GetMediaManagement() (*MediaManagement, error) { return s.GetMediaManagementContext(context.Background()) } -// GetMediaManagement returns the Media Management. +// GetMediaManagementContext returns the Media Management. func (s *Sonarr) GetMediaManagementContext(ctx context.Context) (*MediaManagement, error) { var output MediaManagement diff --git a/sonarr/notification.go b/sonarr/notification.go index 6454c32..917aeea 100644 --- a/sonarr/notification.go +++ b/sonarr/notification.go @@ -149,6 +149,7 @@ func (s *Sonarr) DeleteNotification(notificationID int64) error { return s.DeleteNotificationContext(context.Background(), notificationID) } +// DeleteNotificationContext removes a single notification. func (s *Sonarr) DeleteNotificationContext(ctx context.Context, notificationID int64) error { req := starr.Request{URI: path.Join(bpNotification, starr.Str(notificationID))} if err := s.DeleteAny(ctx, req); err != nil { diff --git a/sonarr/qualitydefinition.go b/sonarr/qualitydefinition.go index dc8f2bd..34204d3 100644 --- a/sonarr/qualitydefinition.go +++ b/sonarr/qualitydefinition.go @@ -83,7 +83,7 @@ func (s *Sonarr) UpdateQualityDefinitionContext( return &output, nil } -// UpdateQualityDefinition updates all quality definitions. +// UpdateQualityDefinitions updates all quality definitions. func (s *Sonarr) UpdateQualityDefinitions(definitions []*QualityDefinition) ([]*QualityDefinition, error) { return s.UpdateQualityDefinitionsContext(context.Background(), definitions) } diff --git a/sonarr/queue.go b/sonarr/queue.go index 06df1ea..9087a47 100644 --- a/sonarr/queue.go +++ b/sonarr/queue.go @@ -58,7 +58,7 @@ func (s *Sonarr) GetQueue(records, perPage int) (*Queue, error) { return s.GetQueueContext(context.Background(), records, perPage) } -// GetQueue returns a single page from the Sonarr Queue (processing, but not yet imported). +// GetQueueContext returns a single page from the Sonarr Queue (processing, but not yet imported). // If you need control over the page, use sonarr.GetQueuePageContext(). func (s *Sonarr) GetQueueContext(ctx context.Context, records, perPage int) (*Queue, error) { queue := &Queue{Records: []*QueueRecord{}} @@ -144,7 +144,7 @@ func (s *Sonarr) QueueGrabContext(ctx context.Context, ids ...int64) error { return fmt.Errorf("json.Marshal(%s): %w", bpQueue, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: path.Join(bpQueue, "grab", "bulk"), Body: &body} if err := s.PostInto(ctx, req, &output); err != nil { diff --git a/sonarr/seasonpass.go b/sonarr/seasonpass.go index 8453832..d2a2fab 100644 --- a/sonarr/seasonpass.go +++ b/sonarr/seasonpass.go @@ -43,7 +43,7 @@ func (s *Sonarr) UpdateSeasonPassContext(ctx context.Context, seasonPass *Season return fmt.Errorf("json.Marshal(%s): %w", bpSeasonPass, err) } - var output interface{} // any ok + var output any // any ok req := starr.Request{URI: bpSeasonPass, Body: &body} if err := s.PostInto(ctx, req, &output); err != nil { diff --git a/sonarr/series.go b/sonarr/series.go index 6ac5773..17d8014 100644 --- a/sonarr/series.go +++ b/sonarr/series.go @@ -66,10 +66,10 @@ type Series struct { Title string `json:"title,omitempty"` TitleSlug string `json:"titleSlug,omitempty"` RootFolderPath string `json:"rootFolderPath,omitempty"` - Added time.Time `json:"added,omitempty"` - FirstAired time.Time `json:"firstAired,omitempty"` - NextAiring time.Time `json:"nextAiring,omitempty"` - PreviousAiring time.Time `json:"previousAiring,omitempty"` + Added time.Time `json:"added,omitzero"` + FirstAired time.Time `json:"firstAired,omitzero"` + NextAiring time.Time `json:"nextAiring,omitzero"` + PreviousAiring time.Time `json:"previousAiring,omitzero"` Ratings *starr.Ratings `json:"ratings,omitempty"` Statistics *Statistics `json:"statistics,omitempty"` Tags []int `json:"tags,omitempty"` @@ -271,7 +271,7 @@ func (s *Sonarr) Lookup(term string) ([]*Series, error) { return s.LookupContext(context.Background(), term) } -// Lookup will search for series matching the specified search term. +// LookupContext will search for series matching the specified search term. // Searches for new shows on TheTVDB.com utilizing sonarr.tv's caching and augmentation proxy. func (s *Sonarr) LookupContext(ctx context.Context, term string) ([]*Series, error) { return s.GetSeriesLookupContext(ctx, term, 0) @@ -284,7 +284,7 @@ func (s *Sonarr) DeleteSeries(seriesID int, deleteFiles bool, importExclude bool return s.DeleteSeriesContext(context.Background(), seriesID, deleteFiles, importExclude) } -// DeleteSeries removes a single Series. +// DeleteSeriesContext removes a single Series. // deleteFiles flag defines the deleteFiles query parameter. // importExclude defines the addImportListExclusion query parameter. func (s *Sonarr) DeleteSeriesContext(ctx context.Context, seriesID int, deleteFiles bool, importExclude bool) error { diff --git a/sonarr/sonarr.go b/sonarr/sonarr.go index 2b77e65..c56bc1f 100644 --- a/sonarr/sonarr.go +++ b/sonarr/sonarr.go @@ -1,3 +1,4 @@ +// Package sonarr is the SDK client for the Sonarr API. package sonarr import ( diff --git a/starrcmd/config.go b/starrcmd/config.go index 881334f..af255d4 100644 --- a/starrcmd/config.go +++ b/starrcmd/config.go @@ -1,3 +1,8 @@ +// Package starrcmd provides the bindings to consume a custom script command hook from any Starr app. +// Use this when you want to write an application that is executed by the Starr app through a +// custom script command hook. +// Create these by going into Settings->Connect->Custom Script in Lidarr, Prowlarr, Radarr, Readarr, or Sonarr. +// See the included example_test.go file for examples on how to use this module. package starrcmd import ( diff --git a/starrcmd/parser.go b/starrcmd/parser.go index d3630fb..5a11043 100644 --- a/starrcmd/parser.go +++ b/starrcmd/parser.go @@ -1,6 +1,3 @@ -// Package starrcmd provides the bindings to consume a custom script command hook from any Starr app. -// Create these by going into Settings->Connect->Custom Script in Lidarr, Prowlarr, Radarr, Readarr, or Sonarr. -// See the included example_test.go file for examples on how to use this module. package starrcmd import ( @@ -14,7 +11,7 @@ import ( // get offloads the error checking from all the other routines. // This is where our journey into the data truly begins. -func (c *CmdEvent) get(wanted Event, output interface{}) error { +func (c *CmdEvent) get(wanted Event, output any) error { if c.Type != wanted { return fmt.Errorf("%w: requested '%s' have '%s'", ErrInvalidEvent, wanted, c.Type) } @@ -27,7 +24,7 @@ func (c *CmdEvent) get(wanted Event, output interface{}) error { } // This does not traverse structs and will only stay on normal members. -func fillStructFromEnv(dataStruct interface{}) error { +func fillStructFromEnv(dataStruct any) error { field := reflect.ValueOf(dataStruct) if field.Kind() != reflect.Ptr || field.Elem().Kind() != reflect.Struct { panic("yuh dun ate in sumthin bahd! This is a bug in the starrcmd library.") diff --git a/starrtest/starrtest.go b/starrtest/starrtest.go index 51429eb..691e30d 100644 --- a/starrtest/starrtest.go +++ b/starrtest/starrtest.go @@ -14,9 +14,9 @@ import ( // This is used by the submodule tests. type MockData struct { // Caller's request. - WithRequest interface{} + WithRequest any // Caller's response. - WithResponse interface{} + WithResponse any // Caller's response. WithError error // A name for the test.