Skip to content

Commit 0578755

Browse files
committed
fix staticcheck lint
1 parent e7c538c commit 0578755

12 files changed

Lines changed: 75 additions & 76 deletions

File tree

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ linters:
1111
- cyclop
1212
- testpackage
1313
- wsl
14-
#fix this
15-
- staticcheck
1614
- embeddedstructfieldcheck # this is a trash rule.
1715
- funcorder # also lame.
1816
- noinlineerr # I like inline errors.

init/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ func (h *Header) makeSection(name section, showHeader, showValue bool) string {
7272
default:
7373
fallthrough
7474
case showValue:
75-
buf.WriteString(fmt.Sprintf("%s%s = %s\n", space, param.Name, param.Value()))
75+
fmt.Fprintf(&buf, "%s%s = %s\n", space, param.Name, param.Value())
7676
case param.Example != nil:
7777
// If example is not empty, use that commented out, otherwise use the default.
7878
fallthrough
7979
case h.Kind == list:
8080
// If the 'kind' is a 'list', we comment all the parameters.
81-
buf.WriteString(fmt.Sprintf("#%s%s = %s\n", space, param.Name, param.Value()))
81+
fmt.Fprintf(&buf, "#%s%s = %s\n", space, param.Name, param.Value())
8282
}
8383
}
8484

init/config/docusaurus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (h *Header) makeDocsTable(prefix string) string {
138138
}
139139
}
140140

141-
buf.WriteString(fmt.Sprintf(tableFormat, param.Name, envVar, def, param.Short))
141+
fmt.Fprintf(&buf, tableFormat, param.Name, envVar, def, param.Short)
142142
}
143143

144144
return buf.String()

pkg/unpackerr/cnfgfile.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (u *Unpackerr) unmarshalConfig() (uint64, uint64, string, error) {
3333
// Load up the default file path and a list of alternate paths.
3434
def, cfl := configFileLocactions()
3535
// Search for one, starting with the default.
36-
for _, configFile = range append([]string{u.Flags.ConfigFile}, cfl...) {
36+
for _, configFile = range append([]string{u.ConfigFile}, cfl...) {
3737
configFile = expandHomedir(configFile)
3838
if _, err := os.Stat(configFile); err == nil {
3939
break // found one, bail out.
@@ -46,20 +46,20 @@ func (u *Unpackerr) unmarshalConfig() (uint64, uint64, string, error) {
4646
msg = msgNoConfigFile
4747

4848
if configFile != "" {
49-
u.Flags.ConfigFile, _ = filepath.Abs(configFile)
50-
msg = msgConfigFound + u.Flags.ConfigFileWithAge()
49+
u.ConfigFile, _ = filepath.Abs(configFile)
50+
msg = msgConfigFound + u.ConfigFileWithAge()
5151

52-
if err := cnfgfile.Unmarshal(u.Config, u.Flags.ConfigFile); err != nil {
52+
if err := cnfgfile.Unmarshal(u.Config, u.ConfigFile); err != nil {
5353
return 0, 0, msg, fmt.Errorf("config file: %w", err)
5454
}
5555
} else if f, err := u.createConfigFile(def); err != nil {
5656
msg = msgConfigFailed + err.Error()
5757
} else if f != "" {
58-
u.Flags.ConfigFile = f
59-
msg = msgConfigCreate + u.Flags.ConfigFileWithAge()
58+
u.ConfigFile = f
59+
msg = msgConfigCreate + u.ConfigFileWithAge()
6060
}
6161

62-
if _, err := cnfg.UnmarshalENV(u.Config, u.Flags.EnvPrefix); err != nil {
62+
if _, err := cnfg.UnmarshalENV(u.Config, u.EnvPrefix); err != nil {
6363
return 0, 0, msg, fmt.Errorf("environment variables: %w", err)
6464
}
6565

@@ -178,7 +178,7 @@ func (u *Unpackerr) validateConfig() (uint64, uint64) { //nolint:cyclop
178178
}
179179

180180
if u.KeepHistory != 0 {
181-
u.History.Items = make([]string, u.KeepHistory)
181+
u.Items = make([]string, u.KeepHistory)
182182
}
183183

184184
return fileMode, dirMode
@@ -317,7 +317,7 @@ func (u *Unpackerr) validateApp(conf *StarrConfig, app starr.App) error {
317317
conf.Protocols = defaultProtocol
318318
}
319319

320-
conf.Config.Client = &http.Client{
320+
conf.Client = &http.Client{
321321
Timeout: conf.Timeout.Duration,
322322
Transport: &http.Transport{
323323
TLSClientConfig: &tls.Config{InsecureSkipVerify: !conf.ValidSSL}, //nolint:gosec

pkg/unpackerr/folder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func (f *Folders) handleFileEvent(name, operation string) {
495495
// processEvent is here to process the event in the `*Unpackerr` scope before sending it back to the `*Folders` scope.
496496
func (u *Unpackerr) processEvent(event *eventData, now time.Time) {
497497
// Do not watch our own log file.
498-
if event.file == u.Config.LogFile || event.file == u.Config.Webserver.LogFile {
498+
if event.file == u.LogFile || event.file == u.Webserver.LogFile {
499499
return
500500
}
501501

pkg/unpackerr/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (u *Unpackerr) extractCompletedDownloads(now time.Time) {
9595
// extractCompletedDownload checks if a completed starr download needs to be queued for extraction.
9696
// This is called by extractCompletedDownloads() via the main routine in start.go.
9797
func (u *Unpackerr) extractCompletedDownload(name string, now time.Time, item *Extract) {
98-
if d := u.Config.StartDelay.Duration - now.Sub(item.Updated); d > time.Second { // wiggle room.
98+
if d := u.StartDelay.Duration - now.Sub(item.Updated); d > time.Second { // wiggle room.
9999
u.Printf("[%s] Waiting for Start Delay: %v (%v remains)", item.App, name, d.Round(time.Second))
100100
return
101101
}
@@ -316,7 +316,7 @@ func (u *Unpackerr) isComplete(status string, protocol starr.Protocol, protos st
316316

317317
// added for https://github.com/Unpackerr/unpackerr/issues/235
318318
func (u *Unpackerr) hasSyncThingFile(dirPath string) string {
319-
files, _ := u.Xtractr.GetFileList(dirPath)
319+
files, _ := u.GetFileList(dirPath)
320320
for _, file := range files {
321321
if strings.HasSuffix(file, ".tmp") {
322322
return file

pkg/unpackerr/history.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ func (u *Unpackerr) updateHistory(item string) {
3030
u.menu[histNone].Hide()
3131
}
3232

33-
u.History.Items[0] = item
33+
u.Items[0] = item
3434

3535
// Do not process 0; this isn't an `intrange`.
36-
for idx := len(u.History.Items) - 1; idx > 0; idx-- {
36+
for idx := len(u.Items) - 1; idx > 0; idx-- {
3737
// u.History.Items is a slice with a set (identical) length and capacity.
38-
switch u.History.Items[idx] = u.History.Items[idx-1]; {
38+
switch u.Items[idx] = u.Items[idx-1]; {
3939
case !ui.HasGUI():
4040
continue
41-
case u.History.Items[idx] != "":
42-
u.menu[hist+strconv.Itoa(idx)].SetTitle(u.History.Items[idx])
41+
case u.Items[idx] != "":
42+
u.menu[hist+strconv.Itoa(idx)].SetTitle(u.Items[idx])
4343
u.menu[hist+strconv.Itoa(idx)].Show()
4444
default:
4545
u.menu[hist+strconv.Itoa(idx)].Hide()

pkg/unpackerr/logs.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,24 @@ func (u *Unpackerr) logCurrentQueue(now time.Time) {
133133
// setupLogging splits log write into a file and/or stdout.
134134
func (u *Unpackerr) setupLogging() {
135135
if u.Config.Debug {
136-
u.Logger.Info.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
137-
u.Logger.Error.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
136+
u.Info.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
137+
u.Error.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
138138
}
139139

140-
u.Config.LogFile = getLogFilePath(u.Config.LogFile, "unpackerr.log")
140+
u.LogFile = getLogFilePath(u.LogFile, "unpackerr.log")
141141
fileMode, _ := strconv.ParseUint(u.LogFileMode, bits8, base32)
142142
rotate := &rotatorr.Config{
143-
Filepath: u.Config.LogFile, // log file name.
144-
FileSize: int64(u.Config.LogFileMb) * megabyte, // megabytes
143+
Filepath: u.LogFile, // log file name.
144+
FileSize: int64(u.LogFileMb) * megabyte, // megabytes
145145
Rotatorr: &timerotator.Layout{
146-
FileCount: u.Config.LogFiles,
146+
FileCount: u.LogFiles,
147147
PostRotate: u.postLogRotate,
148148
}, // number of files to keep.
149149
DirMode: logsDirMode,
150150
FileMode: os.FileMode(fileMode),
151151
}
152152

153-
if u.Config.LogFile != "" {
153+
if u.LogFile != "" {
154154
var err error
155155

156156
u.rotatorr, err = rotatorr.New(rotate)
@@ -167,12 +167,12 @@ func (u *Unpackerr) setupLogging() {
167167
stderr = os.Stderr
168168
}
169169

170-
useLogFile := u.Config.LogFile != "" && u.rotatorr != nil
170+
useLogFile := u.LogFile != "" && u.rotatorr != nil
171171

172172
switch { // only use MultiWriter if we have > 1 writer.
173-
case !u.Config.Quiet && useLogFile:
173+
case !u.Quiet && useLogFile:
174174
u.updateLogOutput(io.MultiWriter(u.rotatorr, os.Stdout), io.MultiWriter(u.rotatorr, stderr))
175-
case !u.Config.Quiet && !useLogFile:
175+
case !u.Quiet && !useLogFile:
176176
u.updateLogOutput(os.Stdout, stderr)
177177
case !useLogFile:
178178
u.updateLogOutput(io.Discard, io.Discard) // default is "nothing"
@@ -198,16 +198,16 @@ func (u *Unpackerr) updateLogOutput(writer io.Writer, errors io.Writer) {
198198
if u.Webserver != nil && u.Webserver.LogFile != "" {
199199
u.setupHTTPLogging()
200200
} else {
201-
u.Logger.HTTP.SetOutput(writer)
201+
u.HTTP.SetOutput(writer)
202202
}
203203

204204
if u.Config.Debug {
205205
u.Logger.Debug.SetOutput(writer)
206206
}
207207

208208
log.SetOutput(errors) // catch out-of-scope garbage
209-
u.Logger.Info.SetOutput(writer)
210-
u.Logger.Error.SetOutput(errors)
209+
u.Info.SetOutput(writer)
210+
u.Error.SetOutput(errors)
211211
u.postLogRotate("", "")
212212
}
213213

@@ -221,14 +221,14 @@ func (u *Unpackerr) setupHTTPLogging() {
221221
}
222222

223223
switch { // only use MultiWriter if we have > 1 writer.
224-
case !u.Config.Quiet && u.Webserver.LogFile != "":
225-
u.Logger.HTTP.SetOutput(io.MultiWriter(rotatorr.NewMust(rotate), os.Stdout))
226-
case !u.Config.Quiet && u.Webserver.LogFile == "":
227-
u.Logger.HTTP.SetOutput(os.Stdout)
228-
case u.Config.Quiet && u.Webserver.LogFile == "":
229-
u.Logger.HTTP.SetOutput(io.Discard)
224+
case !u.Quiet && u.Webserver.LogFile != "":
225+
u.HTTP.SetOutput(io.MultiWriter(rotatorr.NewMust(rotate), os.Stdout))
226+
case !u.Quiet && u.Webserver.LogFile == "":
227+
u.HTTP.SetOutput(os.Stdout)
228+
case u.Quiet && u.Webserver.LogFile == "":
229+
u.HTTP.SetOutput(io.Discard)
230230
default: // u.Config.Quiet && u.Webserver.LogFile != ""
231-
u.Logger.HTTP.SetOutput(rotatorr.NewMust(rotate))
231+
u.HTTP.SetOutput(rotatorr.NewMust(rotate))
232232
}
233233
}
234234

@@ -258,23 +258,23 @@ func (u *Unpackerr) logStartupInfo(msg string, externalFiles map[string]string)
258258
u.logReadarr()
259259
u.logWhisparr()
260260
u.logFolders()
261-
u.Printf(" => Parallel: %d", u.Config.Parallel)
262-
u.Printf(" => Passwords: %d (rar/7z)", len(u.Config.Passwords))
263-
u.Printf(" => Interval / Progress: %s/%s", u.Config.Interval.String(), u.Config.Progress.String())
264-
u.Printf(" => Start/Delete Delay: %s/%s", u.Config.StartDelay.String(), u.Config.DeleteDelay.String())
265-
u.Printf(" => Retry Delay: %v, max: %d", u.Config.RetryDelay, u.Config.MaxRetries)
261+
u.Printf(" => Parallel: %d", u.Parallel)
262+
u.Printf(" => Passwords: %d (rar/7z)", len(u.Passwords))
263+
u.Printf(" => Interval / Progress: %s/%s", u.Interval.String(), u.Progress.String())
264+
u.Printf(" => Start/Delete Delay: %s/%s", u.StartDelay.String(), u.DeleteDelay.String())
265+
u.Printf(" => Retry Delay: %v, max: %d", u.RetryDelay, u.MaxRetries)
266266
u.Printf(" => GUI / StdErr: %v / %v", ui.HasGUI(), u.ErrorStdErr)
267-
u.Printf(" => Debug / Quiet: %v / %v", u.Config.Debug, u.Config.Quiet)
268-
u.Printf(" => Activity / Queues: %v / %s", u.Config.Activity, u.Config.LogQueues.String())
267+
u.Printf(" => Debug / Quiet: %v / %v", u.Config.Debug, u.Quiet)
268+
u.Printf(" => Activity / Queues: %v / %s", u.Activity, u.LogQueues.String())
269269

270270
if runtime.GOOS != windows {
271-
u.Printf(" => Directory & File Modes: %s & %s", u.Config.DirMode, u.Config.FileMode)
271+
u.Printf(" => Directory & File Modes: %s & %s", u.DirMode, u.FileMode)
272272
}
273273

274-
if u.Config.LogFile != "" {
274+
if u.LogFile != "" {
275275
msg := "no rotation"
276-
if u.Config.LogFiles > 0 {
277-
msg = fmt.Sprintf("%d @ %dMb", u.Config.LogFiles, u.Config.LogFileMb)
276+
if u.LogFiles > 0 {
277+
msg = fmt.Sprintf("%d @ %dMb", u.LogFiles, u.LogFileMb)
278278
}
279279

280280
u.Printf(" => Log File: %s (%s, mode: %s)", u.LogFile, msg, u.LogFileMode)

pkg/unpackerr/start.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func Start() error {
140140
log.SetFlags(log.LstdFlags) // in case we throw an error for main.go before logging is setup.
141141

142142
unpackerr := New().ParseFlags() // Grab CLI args (like config file location).
143-
if unpackerr.Flags.verReq {
143+
if unpackerr.verReq {
144144
fmt.Println(version.Print("unpackerr")) //nolint:forbidigo
145145
return nil // don't run anything else.
146146
}
@@ -174,8 +174,8 @@ func Start() error {
174174

175175
unpackerr.logStartupInfo(msg, output)
176176

177-
if unpackerr.Flags.webhook > 0 {
178-
return unpackerr.sampleWebhook(ExtractStatus(unpackerr.Flags.webhook))
177+
if unpackerr.webhook > 0 {
178+
return unpackerr.sampleWebhook(ExtractStatus(unpackerr.webhook))
179179
}
180180

181181
unpackerr.Xtractr = xtractr.NewQueue(&xtractr.Config{
@@ -314,11 +314,11 @@ func dirIsEmpty(path string) bool {
314314

315315
func (u *Unpackerr) watchCmdAndWebhooks() {
316316
for hook := range u.hookChan {
317-
if hook.WebhookConfig.URL != "" {
317+
if hook.URL != "" {
318318
u.sendWebhookWithLog(hook.WebhookConfig, hook.WebhookPayload)
319319
}
320320

321-
if hook.WebhookConfig.Command != "" {
321+
if hook.Command != "" {
322322
u.runCmdhookWithLog(hook.WebhookConfig, hook.WebhookPayload)
323323
}
324324
}
@@ -331,10 +331,10 @@ func (u *Unpackerr) ParseFlags() *Unpackerr {
331331
flag.PrintDefaults()
332332
}
333333

334-
flag.StringVarP(&u.Flags.ConfigFile, "config", "c", os.Getenv("UN_CONFIG_FILE"), "Poller Config File (TOML Format)")
335-
flag.StringVarP(&u.Flags.EnvPrefix, "prefix", "p", "UN", "Environment Variable Prefix")
336-
flag.UintVarP(&u.Flags.webhook, "webhook", "w", 0, "Send test webhook. Valid values: 1,2,3,4,5,6,7,8")
337-
flag.BoolVarP(&u.Flags.verReq, "version", "v", false, "Print the version and exit.")
334+
flag.StringVarP(&u.ConfigFile, "config", "c", os.Getenv("UN_CONFIG_FILE"), "Poller Config File (TOML Format)")
335+
flag.StringVarP(&u.EnvPrefix, "prefix", "p", "UN", "Environment Variable Prefix")
336+
flag.UintVarP(&u.webhook, "webhook", "w", 0, "Send test webhook. Valid values: 1,2,3,4,5,6,7,8")
337+
flag.BoolVarP(&u.verReq, "version", "v", false, "Print the version and exit.")
338338
flag.Parse()
339339

340340
return u // so you can chain into ParseConfig.
@@ -343,11 +343,11 @@ func (u *Unpackerr) ParseFlags() *Unpackerr {
343343
// Run starts the loop that does the work.
344344
func (u *Unpackerr) Run() {
345345
var (
346-
poller = time.NewTicker(u.Config.Interval.Duration) // poll apps at configured interval.
347-
cleaner = time.NewTicker(cleanerInterval) // clean at a fast interval.
348-
xtractr = time.NewTicker(u.Config.StartDelay.Duration) // Check if an extract needs to start.
349-
progress = time.NewTicker(u.Config.Progress.Duration) // Progress update for extractions.
350-
now = version.Started // Used for file system event time stamps.
346+
poller = time.NewTicker(u.Interval.Duration) // poll apps at configured interval.
347+
cleaner = time.NewTicker(cleanerInterval) // clean at a fast interval.
348+
xtractr = time.NewTicker(u.StartDelay.Duration) // Check if an extract needs to start.
349+
progress = time.NewTicker(u.Progress.Duration) // Progress update for extractions.
350+
now = version.Started // Used for file system event time stamps.
351351
)
352352

353353
// Only start the queue/totals log timer when at least one app or folder is configured.

pkg/unpackerr/tray.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (u *Unpackerr) startTray() {
3333
}
3434

3535
func (u *Unpackerr) exitTray() {
36-
u.Xtractr.Stop() // stop and wait for extractions.
36+
u.Stop() // stop and wait for extractions.
3737
// because systray wants to control the exit code? no..
3838
os.Exit(0)
3939
}
@@ -105,8 +105,8 @@ func (u *Unpackerr) watchGuiChannels() {
105105
case <-u.menu["conf"].Clicked():
106106
// does nothing on purpose
107107
case <-u.menu["edit"].Clicked():
108-
u.Printf("User Editing Config File: %s", u.Flags.ConfigFile)
109-
_ = ui.OpenFile(u.Flags.ConfigFile)
108+
u.Printf("User Editing Config File: %s", u.ConfigFile)
109+
_ = ui.OpenFile(u.ConfigFile)
110110
case <-u.menu["link"].Clicked():
111111
// does nothing on purpose
112112
case <-u.menu["info"].Clicked():
@@ -118,8 +118,8 @@ func (u *Unpackerr) watchGuiChannels() {
118118
case <-u.menu["logs"].Clicked():
119119
// does nothing on purpose
120120
case <-u.menu["logs_view"].Clicked():
121-
u.Printf("User Viewing Log File: %s", u.Config.LogFile)
122-
_ = ui.OpenLog(u.Config.LogFile)
121+
u.Printf("User Viewing Log File: %s", u.LogFile)
122+
_ = ui.OpenLog(u.LogFile)
123123
case <-u.menu["logs_rotate"].Clicked():
124124
u.rotateLogs()
125125
case <-u.menu["update"].Clicked():

0 commit comments

Comments
 (0)