diff --git a/Makefile b/Makefile index 26bc7ae..374a8ca 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -export GO_VERSION=1.21.1 +export GO_VERSION=1.21.3 export GOLANGCI_LINT_VERSION=v1.54.0 # configuration/aliases diff --git a/go.mod b/go.mod index 59cbd87..2c73531 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/perebaj/metrica -go 1.21.0 +go 1.21.3 require ( github.com/golangci/golangci-lint v1.54.2 diff --git a/storage.go b/storage.go index 17c2eb8..ab91ad9 100644 --- a/storage.go +++ b/storage.go @@ -8,10 +8,12 @@ import ( "time" ) +// Counter is a struct that holds the datetime of the request type Counter struct { Datetime string } +// Write writes the datetime to the file func Write(f *os.File, c Counter) error { _, err := f.WriteString(fmt.Sprintf("%v\n", c.Datetime)) if err != nil { @@ -20,12 +22,16 @@ func Write(f *os.File, c Counter) error { return nil } +// Read reads the datetime from the file func Read(filename string) ([]time.Time, error) { f, err := os.Open(filename) if err != nil { return nil, fmt.Errorf("error opening file: %v", err) } - defer f.Close() + + defer func() { + _ = f.Close() + }() fileData, err := io.ReadAll(f) if err != nil { diff --git a/storage_test.go b/storage_test.go index fdaba66..a14e500 100644 --- a/storage_test.go +++ b/storage_test.go @@ -15,7 +15,9 @@ func TestWriteRead(t *testing.T) { if err != nil { t.Fatalf("error creating temp file: %v", err) } - defer os.Remove(f.Name()) + defer func() { + _ = os.Remove(f.Name()) + }() if err := Write(f, c); err != nil { t.Fatalf("error writing to file: %v", err)