From ca968950be8b1f307bf61a32a37c3d51c49ab4c6 Mon Sep 17 00:00:00 2001 From: Alexander Gil Date: Wed, 24 Jan 2024 07:55:35 +0100 Subject: [PATCH] refactor: Fix static lint --- go.mod | 9 +++++---- go.sum | 19 ++++++++++--------- helper/helper.go | 5 +---- radarr/add/main.go | 4 ++-- server/repository/repository.go | 7 +++---- server/scheduler/scheduler.go | 9 ++++----- worker/task/encode.go | 9 ++++----- worker/task/pgs.go | 6 +++--- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index c2124a4..e15b213 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.3.2 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/fsnotify/fsnotify v1.4.7 // indirect @@ -51,10 +52,10 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.12.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect + golang.org/x/crypto v0.18.0 // indirect + golang.org/x/net v0.20.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/yaml.v2 v2.2.7 // indirect diff --git a/go.sum b/go.sum index a60a4ab..8144daa 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,9 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -266,8 +267,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= -golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -300,8 +301,8 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= -golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -326,13 +327,13 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/helper/helper.go b/helper/helper.go index 43a407f..263d1d5 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "os" @@ -23,7 +22,6 @@ var ( ApplicationFileName string ValidVideoExtensions = []string{"mp4", "mpg", "m4a", "m4v", "f4v", "f4a", "m4b", "m4r", "f4b", "mov ", "ogg", "oga", "ogv", "ogx ", "wmv", "wma", "asf ", "webm", "avi", "flv", "vob ", "mkv"} STUNServers = []string{"https://api.ipify.org?format=text", "https://ifconfig.me", "https://ident.me/", "https://myexternalip.com/raw"} - updateURL = "https://github.com/pando85/transcoder-server/releases/download/master/%s" workingDirectory = filepath.Join(os.TempDir(), "transcoder") ffmpegPath = "ffmpeg" mkvExtractPath = "mkvextract" @@ -52,7 +50,7 @@ func GetPublicIP() (publicIP string) { return err } defer resp.Body.Close() - publicIPBytes, err := ioutil.ReadAll(resp.Body) + publicIPBytes, err := io.ReadAll(resp.Body) if err != nil { return err } @@ -115,7 +113,6 @@ func DisembedFile(embedFS http.FileSystem, statikPath string, targetFilePath str defer embededFile.Close() if st, _ := embededFile.Stat(); st.IsDir() { err := fs.Walk(embedFS, statikPath, func(path string, info os.FileInfo, err error) error { - //I Dont have time for recurisve if info.IsDir() { return nil } diff --git a/radarr/add/main.go b/radarr/add/main.go index 1995941..3471a42 100644 --- a/radarr/add/main.go +++ b/radarr/add/main.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "os" "sort" @@ -121,7 +121,7 @@ func AddMovieToTranscoderQueue(path string, url string, token string) error { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/server/repository/repository.go b/server/repository/repository.go index 883c6fb..efa196d 100644 --- a/server/repository/repository.go +++ b/server/repository/repository.go @@ -15,7 +15,7 @@ import ( ) var ( - ElementNotFound = fmt.Errorf("element not found") + ErrElementNotFound = fmt.Errorf("element not found") ) type Repository interface { @@ -171,7 +171,7 @@ func (S *SQLRepository) getWorker(ctx context.Context, db Transaction, name stri found = true } if !found { - return nil, fmt.Errorf("%w, %s", ElementNotFound, name) + return nil, fmt.Errorf("%w, %s", ErrElementNotFound, name) } return &worker, err } @@ -253,7 +253,7 @@ func (S *SQLRepository) getJob(ctx context.Context, tx Transaction, uuid string) } rows.Close() if !found { - return nil, fmt.Errorf("%w, %s", ElementNotFound, uuid) + return nil, fmt.Errorf("%w, %s", ErrElementNotFound, uuid) } taskEvents, err := S.getTaskEvents(ctx, tx, video.Id.String()) @@ -427,7 +427,6 @@ func (S *SQLRepository) addVideo(ctx context.Context, tx Transaction, video *mod func (S *SQLRepository) getTimeoutJobs(ctx context.Context, tx Transaction, timeout time.Duration) ([]*model.TaskEvent, error) { timeoutDate := time.Now().Add(-timeout) - timeoutDate.Format(time.RFC3339) rows, err := tx.QueryContext(ctx, "SELECT v.* FROM video_events v right join "+ "(SELECT video_id,max(video_event_id) as video_event_id FROM video_events WHERE notification_type='Job' group by video_id) as m "+ diff --git a/server/scheduler/scheduler.go b/server/scheduler/scheduler.go index 28ccd3b..c6c1dd3 100644 --- a/server/scheduler/scheduler.go +++ b/server/scheduler/scheduler.go @@ -46,7 +46,6 @@ type SchedulerConfig struct { UploadPath string `mapstructure:"uploadPath"` Domain *url.URL MinFileSize int64 `mapstructure:"minFileSize"` - checksums map[string][]byte } type RuntimeScheduler struct { @@ -136,7 +135,7 @@ func (R *RuntimeScheduler) schedule(ctx context.Context) { ForceExecuting: true, Priority: 9, } - video, err = R.scheduleJobRequest(ctx, jobRequest) + _, err = R.scheduleJobRequest(ctx, jobRequest) if err != nil { log.Error(err) } @@ -180,7 +179,7 @@ func (R *RuntimeScheduler) createNewJobRequestByJobRequestDirectory(ctx context. ext := filepath.Ext(relativePathTarget) relativePathTarget = strings.Replace(relativePathTarget, ext, "_encoded.mkv", 1) } - pathFile = filepath.ToSlash(pathFile) + searchJobRequestChan <- &JobRequestResult{ jobRequest: &model.JobRequest{ SourcePath: relativePathSource, @@ -240,7 +239,7 @@ func (R *RuntimeScheduler) scheduleJobRequest(ctx context.Context, jobRequest *m requeueEvent := video.AddEvent(model.NotificationEvent, model.JobNotification, model.ReAddedNotificationStatus) eventsToAdd = append(eventsToAdd, requeueEvent) } else if !(jobRequest.ForceExecuting && status == model.StartedNotificationStatus) { - return errors.New(fmt.Sprintf("%s (%s) job is in %s state by %s, can not be rescheduled", video.Id.String(), jobRequest.SourcePath, lastEvent.Status, lastEvent.WorkerName)) + return fmt.Errorf("%s (%s) job is in %s state by %s, can not be rescheduled", video.Id.String(), jobRequest.SourcePath, lastEvent.Status, lastEvent.WorkerName) } } if len(eventsToAdd) > 0 { @@ -409,7 +408,7 @@ func (R *RuntimeScheduler) GetUploadJobWriter(ctx context.Context, uuid string) path: filePath, temporalPath: temporalPath, }, - }, nil + }, err } func (R *RuntimeScheduler) GetChecksum(ctx context.Context, uuid string) (string, error) { diff --git a/worker/task/encode.go b/worker/task/encode.go index b8a12b4..5eb8a8d 100644 --- a/worker/task/encode.go +++ b/worker/task/encode.go @@ -9,7 +9,6 @@ import ( "fmt" "hash" "io" - "io/ioutil" "mime" "net/http" "os" @@ -264,7 +263,7 @@ func (J *EncodeWorker) calculateChecksum(checksumURL string) (string, error) { return fmt.Errorf("non 200 response in sha265 code %d", respSha256.StatusCode) } - bodyBytes, err := ioutil.ReadAll(respSha256.Body) + bodyBytes, err := io.ReadAll(respSha256.Body) if err != nil { return err } @@ -541,7 +540,7 @@ func (J *EncodeWorker) UploadJob(task *model.WorkTaskEncode, track *TaskTracks) req.ContentLength = fileSize req.Body = reader req.GetBody = func() (io.ReadCloser, error) { - return ioutil.NopCloser(reader), nil + return io.NopCloser(reader), nil } req.Header.Add("checksum", checksum) @@ -717,7 +716,7 @@ func (J *EncodeWorker) convertPGSToSrt(taskEncode *model.WorkTaskEncode, contain if err != nil { return err } - outputBytes, err := ioutil.ReadAll(subFile) + outputBytes, err := io.ReadAll(subFile) if err != nil { return err } @@ -757,7 +756,7 @@ func (J *EncodeWorker) convertPGSToSrt(taskEncode *model.WorkTaskEncode, contain return fmt.Errorf("error on process PGS %d: %s", response.PGSID, response.Err) } subtFilePath := filepath.Join(taskEncode.WorkDir, fmt.Sprintf("%d.srt", response.PGSID)) - err := ioutil.WriteFile(subtFilePath, response.Srt, os.ModePerm) + err := os.WriteFile(subtFilePath, response.Srt, os.ModePerm) if err != nil { return err } diff --git a/worker/task/pgs.go b/worker/task/pgs.go index 237ccac..5e492de 100644 --- a/worker/task/pgs.go +++ b/worker/task/pgs.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strconv" @@ -97,7 +97,7 @@ func (P *PGSWorker) Execute() (err error) { P.Manager.ResponsePGSJob(pgsTaskResponse) }() - err = ioutil.WriteFile(inputFilePath, P.task.PGSdata, os.ModePerm) + err = os.WriteFile(inputFilePath, P.task.PGSdata, os.ModePerm) if err != nil { return err } @@ -123,7 +123,7 @@ func (P *PGSWorker) Execute() (err error) { return err } defer f.Close() - outputBytes, err = ioutil.ReadAll(f) + outputBytes, err = io.ReadAll(f) log.Infof("converted PGS to SRT for job %s stream %d", P.task.Id.String(), P.task.PGSID) return err }