diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-18 12:09:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-18 12:09:43 +0300 |
| commit | 9e63c35bdb3f2a49f60eabb7f7f1ce8e3e7fe6e4 (patch) | |
| tree | 3a0b81d23db9cec370c67f585b70373788926120 | |
| parent | 1a963283a18f9c3a69c92bf5b424748c9813d6d4 (diff) | |
add vet and lint checking - fix some lint errors
| -rw-r--r-- | Taskfile.yml | 7 | ||||
| -rwxr-xr-x | gogios | bin | 6006374 -> 6009349 bytes | |||
| -rw-r--r-- | internal/config.go | 4 | ||||
| -rw-r--r-- | internal/notify.go | 6 | ||||
| -rw-r--r-- | internal/run.go | 9 | ||||
| -rw-r--r-- | internal/state.go | 6 |
6 files changed, 23 insertions, 9 deletions
diff --git a/Taskfile.yml b/Taskfile.yml index fb6b3bc..d910237 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,3 +4,10 @@ tasks: build: cmds: - go build -o gogios cmd/gogios/main.go + check: + cmds: + - go vet **/*.go + - golangci-lint run + lint-install: + cmds: + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest Binary files differdiff --git a/internal/config.go b/internal/config.go index a57ea9e..ec6f6fd 100644 --- a/internal/config.go +++ b/internal/config.go @@ -3,7 +3,7 @@ package internal import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "os" ) @@ -27,7 +27,7 @@ func newConfig(configFile string) (config, error) { } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return conf, err } diff --git a/internal/notify.go b/internal/notify.go index 991743d..a89035b 100644 --- a/internal/notify.go +++ b/internal/notify.go @@ -29,6 +29,8 @@ func notify(conf config, subject, body string) error { []string{conf.EmailTo}, []byte(message)) } -func notifyError(conf config, err error) error { - return notify(conf, fmt.Sprintf("GOGIOS: An error occured: %v", err), err.Error()) +func notifyError(conf config, err error) { + if err := notify(conf, fmt.Sprintf("GOGIOS: An error occured: %v", err), err.Error()); err != nil { + log.Println("error: ", err) + } } diff --git a/internal/run.go b/internal/run.go index 586ebbd..0fd0ef1 100644 --- a/internal/run.go +++ b/internal/run.go @@ -1,6 +1,9 @@ package internal -import "context" +import ( + "context" + "log" +) func Run(ctx context.Context, configFile string, renotify bool) { conf, err := newConfig(configFile) @@ -24,6 +27,8 @@ func Run(ctx context.Context, configFile string, renotify bool) { } if subject, body, doNotify := state.report(renotify); doNotify { - notify(conf, subject, body) + if err := notify(conf, subject, body); err != nil { + log.Println("error:", err) + } } } diff --git a/internal/state.go b/internal/state.go index f23c8a4..f7e03cf 100644 --- a/internal/state.go +++ b/internal/state.go @@ -3,7 +3,7 @@ package internal import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -42,7 +42,7 @@ func readState(conf config) (state, error) { } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return s, err } @@ -91,7 +91,7 @@ func (s state) persist() error { return err } - return ioutil.WriteFile(s.stateFile, jsonData, os.ModePerm) + return os.WriteFile(s.stateFile, jsonData, os.ModePerm) } func (s state) report(renotify bool) (string, string, bool) { |
