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

Commit

Permalink
fix go linter complains
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Jul 16, 2021
1 parent e32b0dc commit eb8d1c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (s *Server) Run(version string) error {
if err := viper.WriteConfigAs(ymlcf); err != nil {
return err
}
return fmt.Errorf("Config file converted and written to: %s", ymlcf)
return fmt.Errorf("ERROR: Config file converted and written to: %s", ymlcf)
}

if err := detectDiskStat(c.DownloadDirectory); err != nil {
Expand Down
24 changes: 12 additions & 12 deletions server/server_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

var (
errInvalidReq = errors.New("INVALID REQUEST")
errUnknowAct = errors.New("Unkown Action")
errUnknowPath = errors.New("Unkown Path")
errUnknowAct = errors.New("UNKOWN ACTION")
errUnknowPath = errors.New("UNKOWN PATH")
)

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

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

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

//convert url into torrent bytes
if action == "url" {
url := string(data)
remote, err := http.Get(url)
if err != nil {
return fmt.Errorf("Invalid remote torrent URL: %s %w", url, err)
return fmt.Errorf("ERROR: Invalid remote torrent URL: %s %w", url, err)
}
defer remote.Body.Close()
if remote.ContentLength > 512*1024 {
//enforce max body size (512k)
return fmt.Errorf("Remote torrent too large")
return fmt.Errorf("ERROR: Remote torrent too large")
}
data, err = ioutil.ReadAll(remote.Body)
if err != nil {
return fmt.Errorf("Failed to download remote torrent: %w", err)
return fmt.Errorf("ERROR: Failed to download remote torrent: %w", err)
}
action = "torrentfile"
}
Expand All @@ -144,7 +144,7 @@ func (s *Server) apiPOST(r *http.Request) error {
if errors.Is(err, engine.ErrMaxConnTasks) {
return nil
}
return fmt.Errorf("Magnet error: %w", err)
return fmt.Errorf("ERROR: Magnet error: %w", err)
}
case "torrent":
cmd := strings.SplitN(string(data), ":", 2)
Expand Down Expand Up @@ -173,7 +173,7 @@ func (s *Server) apiPOST(r *http.Request) error {
}
s.engine.PushWaitTask(infohash)
default:
return fmt.Errorf("Invalid state: %s", state)
return fmt.Errorf("ERROR: Invalid state: %s", state)
}
case "file":
cmd := strings.SplitN(string(data), ":", 3)
Expand All @@ -193,10 +193,10 @@ func (s *Server) apiPOST(r *http.Request) error {
return err
}
default:
return fmt.Errorf("Invalid state: %s", state)
return fmt.Errorf("ERROR: Invalid state: %s", state)
}
default:
return fmt.Errorf("Invalid action: %s", action)
return fmt.Errorf("ERROR: Invalid action: %s", action)
}
return nil
}
Expand All @@ -220,7 +220,7 @@ func (s *Server) apiConfigure(data []byte) error {

if status&engine.ForbidRuntimeChange > 0 {
log.Printf("[api] warnning! someone tried to change DoneCmd config")
return errors.New("Nice Try! But this is NOT allowed being changed on runtime")
return errors.New("ERROR: This item is NOT allowed being changed on runtime")
}
if status&engine.NeedRestartWatch > 0 {
s.engine.StartTorrentWatcher()
Expand Down
4 changes: 3 additions & 1 deletion server/server_bg.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func (s *Server) backgroundRoutines() {
}

s.updateRSS()
for range time.Tick(30 * time.Minute) {
tk := time.NewTicker(30 * time.Minute)
defer tk.Stop()
for range tk.C {
s.updateRSS()
}
}()
Expand Down
6 changes: 3 additions & 3 deletions server/server_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func (s *Server) serveDownloadFiles(w http.ResponseWriter, r *http.Request) {

func list(path string, info os.FileInfo, node *fsNode, n *uint) error {
if (!info.IsDir() && !info.Mode().IsRegular()) || strings.HasPrefix(info.Name(), ".") {
return errors.New("Non-regular file")
return errors.New("ERROR: Non-regular file")
}
(*n)++
if (*n) > fileNumberLimit {
return errors.New("Over file limit") //limit number of files walked
return errors.New("ERROR: Over file limit") //limit number of files walked
}
node.Name = info.Name()
node.Size = info.Size()
Expand All @@ -91,7 +91,7 @@ func list(path string, info os.FileInfo, node *fsNode, n *uint) error {
}
children, err := ioutil.ReadDir(path)
if err != nil {
return fmt.Errorf("Failed to list files: %w", err)
return fmt.Errorf("ERROR: Failed to list files: %w", err)
}
node.Size = 0
for _, i := range children {
Expand Down

0 comments on commit eb8d1c5

Please sign in to comment.