diff --git a/Makefile b/Makefile index 43e4c18..e007882 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ vet: golangci: ifndef HAS_GOLANGCI - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.26.0 + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.49.0 endif golangci-lint run ./... @@ -86,7 +86,7 @@ cover: work prepare: ifndef HAS_GOLANGCI - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.26.0 + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.49.0 endif echo "golangci-lint already installed" ifndef HAS_GOIMPORTS diff --git a/pkg/api/items.go b/pkg/api/items.go index b4eef0d..1e4b516 100644 --- a/pkg/api/items.go +++ b/pkg/api/items.go @@ -22,7 +22,7 @@ func (bit *convertibleBoolean) UnmarshalJSON(data []byte) error { return nil } -//Result API result interface +// Result API result interface type Result interface { GetWord() string Error() string @@ -44,7 +44,7 @@ type apiError struct { ErrorCode int `json:"error_code"` } -//Word translates word structure +// Word translates word structure type Word struct { ID int `json:"id"` Votes int `json:"votes"` @@ -53,7 +53,7 @@ type Word struct { Exists convertibleBoolean `json:"ut"` } -//OpResult represents operation result +// OpResult represents operation result type OpResult struct { Error error Result Result @@ -68,7 +68,7 @@ func opResultFromBody(word string, body string) OpResult { } } -//TranslationResult represents API response +// TranslationResult represents API response type TranslationResult struct { Word string `json:"-"` Words []string `json:"-"` @@ -80,22 +80,22 @@ type TranslationResult struct { DirectionEnglish bool `json:"directionEnglish"` } -//FromResponse fills TranslationResult from http response +// FromResponse fills TranslationResult from http response func (result *TranslationResult) FromResponse(body string) error { return fromResponse(result, body) } -//GetTranscription returns word transcription +// GetTranscription returns word transcription func (result *TranslationResult) GetTranscription() []string { return []string{result.Transcription} } -//PrintTranslation prints transcription +// PrintTranslation prints transcription func (result *TranslationResult) PrintTranslation() { printTranslation(result) } -//PrintAddedTranslation prints transcription diring adding operation +// PrintAddedTranslation prints transcription diring adding operation func (result *TranslationResult) PrintAddedTranslation() { printAddedTranslation(result) } @@ -110,22 +110,22 @@ func (result *TranslationResult) parse() { result.Words = utils.Unique(result.Words) } -//GetWord returns word to translate +// GetWord returns word to translate func (result *TranslationResult) GetWord() string { return result.Word } -//SetWord sets word to translate +// SetWord sets word to translate func (result *TranslationResult) SetWord(word string) { result.Word = word } -//GetTranslate returns translation for a word +// GetTranslate returns translation for a word func (result *TranslationResult) GetTranslate() []string { return result.Words } -//SetTranslate sets custom translation for a word +// SetTranslate sets custom translation for a word func (result *TranslationResult) SetTranslate(translates []string, replace bool) { if replace { result.Words = utils.Unique(translates) @@ -134,12 +134,12 @@ func (result *TranslationResult) SetTranslate(translates []string, replace bool) } } -//GetSoundURLs returns sound urls to pronounce +// GetSoundURLs returns sound urls to pronounce func (result *TranslationResult) GetSoundURLs() []string { return []string{result.SoundURL} } -//InDictionary checks either word is already has been added into the dictionary +// InDictionary checks either word is already has been added into the dictionary func (result *TranslationResult) InDictionary() bool { if bool(result.Exists) { return true @@ -156,12 +156,12 @@ func (result *TranslationResult) Error() string { return result.ErrorMsg } -//IsRussian either word in in Russian language +// IsRussian either word in in Russian language func (result *TranslationResult) IsRussian() bool { return result.Transcription == "" } -//NoResult negative operation result +// NoResult negative operation result type NoResult struct { Translate []string `json:"translate"` ErrorMsg string `json:"error_msg"` diff --git a/pkg/api/utils.go b/pkg/api/utils.go index ebc1c7d..81b89d5 100644 --- a/pkg/api/utils.go +++ b/pkg/api/utils.go @@ -3,7 +3,7 @@ package api import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -23,7 +23,7 @@ func readBody(resp *http.Response) (*string, error) { logger.Error(err) } }() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/files/download.go b/pkg/files/download.go index 62c08ab..4cdb833 100644 --- a/pkg/files/download.go +++ b/pkg/files/download.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "os" "sync" @@ -49,7 +48,7 @@ func NewFileDownloader(url string) Downloader { // GetWriter prepares WriteCloser for temporary file func (f *FileDownloader) GetWriter() (io.WriteCloser, string, error) { - fl, err := ioutil.TempFile(filePath, fileTemplate) + fl, err := os.CreateTemp(filePath, fileTemplate) if err != nil { return nil, "", err } diff --git a/pkg/translator/args.go b/pkg/translator/args.go index 3ccb53f..80a7d17 100644 --- a/pkg/translator/args.go +++ b/pkg/translator/args.go @@ -3,7 +3,6 @@ package translator import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -53,7 +52,7 @@ func (cf *configFile) decode(data []byte, args *Lingualeo) error { } func (cf *configFile) decodeFile(args *Lingualeo) error { - data, err := ioutil.ReadFile(cf.filename) + data, err := os.ReadFile(cf.filename) if err != nil { return err } @@ -99,7 +98,7 @@ func prepareCliArgs(version string) Lingualeo { app.ArgsUsage = "Multiple words can be supplied" app.Action = defaultCommand app.Description = ` - It is possible to use config file to set predefined parameters + It is possible to use config file to set predefined parameters Default config files are: ~/lingualeo.[toml|yml|yaml|json] Toml format example: @@ -110,18 +109,18 @@ func prepareCliArgs(version string) Lingualeo { sound = true player = "mplayer" download = false - + Yaml format example: - + email: email@gmail.com password: password add: false sound: true player: mplayer download: false - + JSON format example: - + { "email": "email@gmail.com", "password": "password", diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 87d106d..01fba1d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "os/exec" @@ -40,7 +39,7 @@ func ReadBody(resp *http.Response) (*string, error) { logger.Error(err) } }() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return nil, err }