Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit eb8d1c5

Browse files
committed
fix go linter complains
1 parent e32b0dc commit eb8d1c5

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (s *Server) Run(version string) error {
164164
if err := viper.WriteConfigAs(ymlcf); err != nil {
165165
return err
166166
}
167-
return fmt.Errorf("Config file converted and written to: %s", ymlcf)
167+
return fmt.Errorf("ERROR: Config file converted and written to: %s", ymlcf)
168168
}
169169

170170
if err := detectDiskStat(c.DownloadDirectory); err != nil {

server/server_api.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717

1818
var (
1919
errInvalidReq = errors.New("INVALID REQUEST")
20-
errUnknowAct = errors.New("Unkown Action")
21-
errUnknowPath = errors.New("Unkown Path")
20+
errUnknowAct = errors.New("UNKOWN ACTION")
21+
errUnknowPath = errors.New("UNKOWN PATH")
2222
)
2323

2424
func (s *Server) apiGET(w http.ResponseWriter, r *http.Request) error {
@@ -95,29 +95,29 @@ func (s *Server) apiPOST(r *http.Request) error {
9595

9696
action := strings.TrimPrefix(r.URL.Path, "/api/")
9797
if r.Method != "POST" {
98-
return fmt.Errorf("Invalid request method (expecting POST)")
98+
return fmt.Errorf("ERROR: Invalid request method (expecting POST)")
9999
}
100100

101101
data, err := ioutil.ReadAll(r.Body)
102102
if err != nil {
103-
return fmt.Errorf("Failed to download request body: %w", err)
103+
return fmt.Errorf("ERROR: Failed to download request body: %w", err)
104104
}
105105

106106
//convert url into torrent bytes
107107
if action == "url" {
108108
url := string(data)
109109
remote, err := http.Get(url)
110110
if err != nil {
111-
return fmt.Errorf("Invalid remote torrent URL: %s %w", url, err)
111+
return fmt.Errorf("ERROR: Invalid remote torrent URL: %s %w", url, err)
112112
}
113113
defer remote.Body.Close()
114114
if remote.ContentLength > 512*1024 {
115115
//enforce max body size (512k)
116-
return fmt.Errorf("Remote torrent too large")
116+
return fmt.Errorf("ERROR: Remote torrent too large")
117117
}
118118
data, err = ioutil.ReadAll(remote.Body)
119119
if err != nil {
120-
return fmt.Errorf("Failed to download remote torrent: %w", err)
120+
return fmt.Errorf("ERROR: Failed to download remote torrent: %w", err)
121121
}
122122
action = "torrentfile"
123123
}
@@ -144,7 +144,7 @@ func (s *Server) apiPOST(r *http.Request) error {
144144
if errors.Is(err, engine.ErrMaxConnTasks) {
145145
return nil
146146
}
147-
return fmt.Errorf("Magnet error: %w", err)
147+
return fmt.Errorf("ERROR: Magnet error: %w", err)
148148
}
149149
case "torrent":
150150
cmd := strings.SplitN(string(data), ":", 2)
@@ -173,7 +173,7 @@ func (s *Server) apiPOST(r *http.Request) error {
173173
}
174174
s.engine.PushWaitTask(infohash)
175175
default:
176-
return fmt.Errorf("Invalid state: %s", state)
176+
return fmt.Errorf("ERROR: Invalid state: %s", state)
177177
}
178178
case "file":
179179
cmd := strings.SplitN(string(data), ":", 3)
@@ -193,10 +193,10 @@ func (s *Server) apiPOST(r *http.Request) error {
193193
return err
194194
}
195195
default:
196-
return fmt.Errorf("Invalid state: %s", state)
196+
return fmt.Errorf("ERROR: Invalid state: %s", state)
197197
}
198198
default:
199-
return fmt.Errorf("Invalid action: %s", action)
199+
return fmt.Errorf("ERROR: Invalid action: %s", action)
200200
}
201201
return nil
202202
}
@@ -220,7 +220,7 @@ func (s *Server) apiConfigure(data []byte) error {
220220

221221
if status&engine.ForbidRuntimeChange > 0 {
222222
log.Printf("[api] warnning! someone tried to change DoneCmd config")
223-
return errors.New("Nice Try! But this is NOT allowed being changed on runtime")
223+
return errors.New("ERROR: This item is NOT allowed being changed on runtime")
224224
}
225225
if status&engine.NeedRestartWatch > 0 {
226226
s.engine.StartTorrentWatcher()

server/server_bg.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func (s *Server) backgroundRoutines() {
3434
}
3535

3636
s.updateRSS()
37-
for range time.Tick(30 * time.Minute) {
37+
tk := time.NewTicker(30 * time.Minute)
38+
defer tk.Stop()
39+
for range tk.C {
3840
s.updateRSS()
3941
}
4042
}()

server/server_files.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ func (s *Server) serveDownloadFiles(w http.ResponseWriter, r *http.Request) {
7777

7878
func list(path string, info os.FileInfo, node *fsNode, n *uint) error {
7979
if (!info.IsDir() && !info.Mode().IsRegular()) || strings.HasPrefix(info.Name(), ".") {
80-
return errors.New("Non-regular file")
80+
return errors.New("ERROR: Non-regular file")
8181
}
8282
(*n)++
8383
if (*n) > fileNumberLimit {
84-
return errors.New("Over file limit") //limit number of files walked
84+
return errors.New("ERROR: Over file limit") //limit number of files walked
8585
}
8686
node.Name = info.Name()
8787
node.Size = info.Size()
@@ -91,7 +91,7 @@ func list(path string, info os.FileInfo, node *fsNode, n *uint) error {
9191
}
9292
children, err := ioutil.ReadDir(path)
9393
if err != nil {
94-
return fmt.Errorf("Failed to list files: %w", err)
94+
return fmt.Errorf("ERROR: Failed to list files: %w", err)
9595
}
9696
node.Size = 0
9797
for _, i := range children {

0 commit comments

Comments
 (0)