Skip to content

Commit

Permalink
Removed deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
trezorg committed Aug 29, 2022
1 parent 9d7b5e2 commit b999ace
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...

Expand All @@ -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
Expand Down
32 changes: 16 additions & 16 deletions pkg/api/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand All @@ -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
Expand All @@ -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:"-"`
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/files/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/translator/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package translator
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand All @@ -110,18 +109,18 @@ func prepareCliArgs(version string) Lingualeo {
sound = true
player = "mplayer"
download = false
Yaml format example:
email: [email protected]
password: password
add: false
sound: true
player: mplayer
download: false
JSON format example:
{
"email": "[email protected]",
"password": "password",
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b999ace

Please sign in to comment.