Skip to content

Commit

Permalink
refactor: Fix static lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pando85 committed Jan 24, 2024
1 parent 204f4a7 commit ca96895
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 36 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
5 changes: 1 addition & 4 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions radarr/add/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"sort"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions server/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
ElementNotFound = fmt.Errorf("element not found")
ErrElementNotFound = fmt.Errorf("element not found")
)

type Repository interface {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 "+
Expand Down
9 changes: 4 additions & 5 deletions server/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions worker/task/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"mime"
"net/http"
"os"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions worker/task/pgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit ca96895

Please sign in to comment.