diff --git a/lc-lib/admin/client.go b/lc-lib/admin/client.go index 4cb6a0b7e..54f609da2 100644 --- a/lc-lib/admin/client.go +++ b/lc-lib/admin/client.go @@ -20,7 +20,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -177,7 +177,7 @@ func (c *Client) Call(path string, values url.Values) (string, error) { } func (c *Client) handleResponse(resp *http.Response) (string, error) { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/lc-lib/config/generate/platform.go b/lc-lib/config/generate/platform.go index 324a2d776..08a76e110 100644 --- a/lc-lib/config/generate/platform.go +++ b/lc-lib/config/generate/platform.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "strings" @@ -66,7 +65,7 @@ func main() { platformFile += generateInit(config) platformFileBytes := []byte(os.ExpandEnv(platformFile)) - if err := ioutil.WriteFile(targetFile, platformFileBytes, 0644); err != nil { + if err := os.WriteFile(targetFile, platformFileBytes, 0644); err != nil { log.Fatalf("Failed to write %s: %s", targetFile, err) } } @@ -152,37 +151,37 @@ func generateInitSegment(pkg, name string) string { // // Examples // -// "" => [""] -// "lowercase" => ["lowercase"] -// "Class" => ["Class"] -// "MyClass" => ["My", "Class"] -// "MyC" => ["My", "C"] -// "HTML" => ["HTML"] -// "PDFLoader" => ["PDF", "Loader"] -// "AString" => ["A", "String"] -// "SimpleXMLParser" => ["Simple", "XML", "Parser"] -// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] -// "GL11Version" => ["GL", "11", "Version"] -// "99Bottles" => ["99", "Bottles"] -// "May5" => ["May", "5"] -// "BFG9000" => ["BFG", "9000"] -// "BöseÜberraschung" => ["Böse", "Überraschung"] -// "Two spaces" => ["Two", " ", "spaces"] -// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] +// "" => [""] +// "lowercase" => ["lowercase"] +// "Class" => ["Class"] +// "MyClass" => ["My", "Class"] +// "MyC" => ["My", "C"] +// "HTML" => ["HTML"] +// "PDFLoader" => ["PDF", "Loader"] +// "AString" => ["A", "String"] +// "SimpleXMLParser" => ["Simple", "XML", "Parser"] +// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] +// "GL11Version" => ["GL", "11", "Version"] +// "99Bottles" => ["99", "Bottles"] +// "May5" => ["May", "5"] +// "BFG9000" => ["BFG", "9000"] +// "BöseÜberraschung" => ["Böse", "Überraschung"] +// "Two spaces" => ["Two", " ", "spaces"] +// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] // // Splitting rules // -// 1) If string is not valid UTF-8, return it without splitting as +// 1. If string is not valid UTF-8, return it without splitting as // single item array. -// 2) Assign all unicode characters into one of 4 sets: lower case +// 2. Assign all unicode characters into one of 4 sets: lower case // letters, upper case letters, numbers, and all other characters. -// 3) Iterate through characters of string, introducing splits +// 3. Iterate through characters of string, introducing splits // between adjacent characters that belong to different sets. -// 4) Iterate through array of split strings, and if a given string +// 4. Iterate through array of split strings, and if a given string // is upper case: -// if subsequent string is lower case: -// move last character of upper case string to beginning of -// lower case string +// if subsequent string is lower case: +// move last character of upper case string to beginning of +// lower case string func split(src string) (entries []string) { // don't split invalid utf8 if !utf8.ValidString(src) { diff --git a/lc-lib/config/yaml.go b/lc-lib/config/yaml.go index 9f6ace042..97ac9017b 100644 --- a/lc-lib/config/yaml.go +++ b/lc-lib/config/yaml.go @@ -17,7 +17,7 @@ package config import ( - "io/ioutil" + "os" "gopkg.in/yaml.v2" ) @@ -27,7 +27,7 @@ func loadYAMLFile(path string, rawConfig interface{}) (err error) { var data []byte // Read the entire file - if data, err = ioutil.ReadFile(path); err != nil { + if data, err = os.ReadFile(path); err != nil { return } diff --git a/lc-lib/core/logging.go b/lc-lib/core/logging.go index 067a090dc..f74846bbe 100644 --- a/lc-lib/core/logging.go +++ b/lc-lib/core/logging.go @@ -17,7 +17,7 @@ package core import ( - "io/ioutil" + "io" golog "log" "os" @@ -81,7 +81,7 @@ func (f *defaultLogBackend) Reopen() (err error) { func (f *defaultLogBackend) Close() { // Discard logs before closing - golog.SetOutput(ioutil.Discard) + golog.SetOutput(io.Discard) if f.file != nil { f.file.Close() diff --git a/lc-lib/transports/common.go b/lc-lib/transports/common.go index ec6ac62d8..90003e5b8 100644 --- a/lc-lib/transports/common.go +++ b/lc-lib/transports/common.go @@ -23,7 +23,7 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" + "os" "github.com/driskell/log-courier/lc-lib/config" ) @@ -308,7 +308,7 @@ func GetTlsVersionAsString(version uint16) string { // AddCertificates returns a new slice containing the given certificate list and the contents of the given file added func AddCertificates(certificateList []*x509.Certificate, file string) ([]*x509.Certificate, error) { - pemdata, err := ioutil.ReadFile(file) + pemdata, err := os.ReadFile(file) if err != nil { return nil, err } diff --git a/lc-lib/transports/es/bulkrequest_test.go b/lc-lib/transports/es/bulkrequest_test.go index 7d022c71f..3a568dff6 100644 --- a/lc-lib/transports/es/bulkrequest_test.go +++ b/lc-lib/transports/es/bulkrequest_test.go @@ -20,7 +20,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "testing" "time" @@ -59,7 +59,7 @@ func TestRequestCreate(t *testing.T) { func TestRequestReadFull(t *testing.T) { request := createTestBulkRequest(3, "2020-03-07", "2020-03-07") - result, err := ioutil.ReadAll(request) + result, err := io.ReadAll(request) if err != nil { t.Errorf("Failed to encode: %s", err) } @@ -87,7 +87,7 @@ func TestRequestReadFull(t *testing.T) { func TestRequestReadMultiple(t *testing.T) { request := createTestBulkRequest(3, "2020-03-07", "2020-03-14") - result, err := ioutil.ReadAll(request) + result, err := io.ReadAll(request) if err != nil { t.Errorf("Failed to encode: %s", err) } @@ -115,10 +115,10 @@ func TestRequestReadMultiple(t *testing.T) { func TestRequestReadReset(t *testing.T) { request := createTestBulkRequest(3, "2020-03-07", "2020-03-14") - if _, err := ioutil.ReadAll(request); err != nil { + if _, err := io.ReadAll(request); err != nil { t.Errorf("Failed to encode: %s", err) } - result, err := ioutil.ReadAll(request) + result, err := io.ReadAll(request) if err != nil { t.Errorf("Failed to encode: %s", err) } @@ -126,7 +126,7 @@ func TestRequestReadReset(t *testing.T) { t.Errorf("Unexpected result: %s", string(result)) } request.Reset() - result, err = ioutil.ReadAll(request) + result, err = io.ReadAll(request) if err != nil { t.Errorf("Failed to encode: %s", err) } @@ -159,7 +159,7 @@ func TestRequestMark(t *testing.T) { t.Errorf("Unexpected ack sequence: %d", request.AckSequence()) } request.Reset() - result, err := ioutil.ReadAll(request) + result, err := io.ReadAll(request) if err != nil { t.Errorf("Failed to encode: %s", err) } diff --git a/lc-lib/transports/es/transportes.go b/lc-lib/transports/es/transportes.go index 4977d9af7..c12642dcf 100644 --- a/lc-lib/transports/es/transportes.go +++ b/lc-lib/transports/es/transportes.go @@ -27,7 +27,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "strings" @@ -158,11 +157,11 @@ func (t *transportES) populateNodeInfo() error { return err } defer func() { - bufio.NewReader(httpResponse.Body).WriteTo(ioutil.Discard) + bufio.NewReader(httpResponse.Body).WriteTo(io.Discard) httpResponse.Body.Close() }() if httpResponse.StatusCode != 200 { - body, _ := ioutil.ReadAll(httpResponse.Body) + body, _ := io.ReadAll(httpResponse.Body) return fmt.Errorf("unexpected status: %s [Body: %s]", httpResponse.Status, body) } @@ -239,11 +238,11 @@ func (t *transportES) installTemplate() error { return err } defer func() { - bufio.NewReader(httpResponse.Body).WriteTo(ioutil.Discard) + bufio.NewReader(httpResponse.Body).WriteTo(io.Discard) httpResponse.Body.Close() }() if httpResponse.StatusCode != 200 { - body, _ := ioutil.ReadAll(httpResponse.Body) + body, _ := io.ReadAll(httpResponse.Body) return fmt.Errorf("unexpected status: %s [Body: %s]", httpResponse.Status, body) } @@ -264,14 +263,14 @@ func (t *transportES) checkTemplate(server *net.TCPAddr, name string) (bool, err return false, err } defer func() { - bufio.NewReader(httpResponse.Body).WriteTo(ioutil.Discard) + bufio.NewReader(httpResponse.Body).WriteTo(io.Discard) httpResponse.Body.Close() }() if httpResponse.StatusCode == 200 { return true, nil } if httpResponse.StatusCode != 404 { - body, _ := ioutil.ReadAll(httpResponse.Body) + body, _ := io.ReadAll(httpResponse.Body) return false, fmt.Errorf("unexpected status: %s [Body: %s]", httpResponse.Status, body) } @@ -381,7 +380,7 @@ func (t *transportES) performBulkRequest(id int, request *bulkRequest) error { if err != nil { return err } - body, _ := ioutil.ReadAll(httpResponse.Body) + body, _ := io.ReadAll(httpResponse.Body) httpResponse.Body.Close() if httpResponse.StatusCode != 200 { return fmt.Errorf("unexpected status: %s [Body: %s]", httpResponse.Status, body) diff --git a/lc-lib/transports/es/transportesfactory.go b/lc-lib/transports/es/transportesfactory.go index f5e591c18..836dcad83 100644 --- a/lc-lib/transports/es/transportesfactory.go +++ b/lc-lib/transports/es/transportesfactory.go @@ -20,7 +20,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "reflect" @@ -108,7 +108,7 @@ func (f *TransportESFactory) Validate(p *config.Parser, configPath string) (err defer func() { file.Close() }() - f.template, err = ioutil.ReadAll(file) + f.template, err = io.ReadAll(file) if err != nil { return }