Skip to content

Commit

Permalink
🐛 chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
perebaj committed Oct 11, 2023
1 parent 0a126c5 commit fc154c4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fc154c4

Please sign in to comment.