Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestEditArgs(t *testing.T) {
t.Run(testItem.name, func(t *testing.T) {
if testItem.provided != nil {
var whenString string
if (testItem.provided.When == time.Time{}) {
if (testItem.provided.When.Equal(time.Time{})) {
whenString = helpers.TimeFormat(time.Now())
} else {
whenString = helpers.TimeFormat(testItem.provided.When)
Expand Down
8 changes: 4 additions & 4 deletions cli/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func init() {
// verifySingleFormat ensures that there is only 1 output format used.
func verifySingleFormat() {
if !printOutputPretty && !printOutputYAML && !printOutputJSON {
defaultFormat := viper.GetString("default.format")
if defaultFormat == "yaml" || defaultFormat == "yml" {
switch viper.GetString("default.format") {
case "yaml", "yml":
printOutputYAML = true
} else if defaultFormat == "json" {
case "json":
printOutputJSON = true
} else {
default:
printOutputPretty = true
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion model/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type prettyWork struct {
// NewWork is the generator for work.
func NewWork(title, description, author string, duration int, tags []string, when time.Time) *Work {
now, _ := helpers.GetStringAsDateTime(helpers.TimeFormat(time.Now()))
if (when == time.Time{}) {
if (when.Equal(time.Time{})) {
when = now
}
sort.Strings(tags)
Expand Down
2 changes: 1 addition & 1 deletion model/work_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestNewWork(t *testing.T) {

// Instead of mocking ID and time.Now(), just set the
// result of it to the expected value
if (testItem.wWhen == time.Time{}) {
if (testItem.wWhen.Equal(time.Time{})) {
assert.Equal(t, actual.When, actual.CreatedAt)
assert.Equal(t, actual.WhenQueryEpoch, actual.CreatedAt.Unix())

Expand Down
20 changes: 15 additions & 5 deletions repository/bboltRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func (*bboltRepo) Init() error {
helpers.LogError(fmt.Sprintf("Error opening file: %s", openErr.Error()), "read db error - bolt")
return openErr
}
defer db.Close()
defer func() {
_ = db.Close()
}()

viewErr := db.Select(
q.Eq("WhenQueryEpoch", 0)).Find(&foundWls)
Expand Down Expand Up @@ -68,7 +70,9 @@ func (*bboltRepo) Save(wl *model.Work) error {
helpers.LogError(fmt.Sprintf("Error opening file: %s", openErr.Error()), "read db error - bolt")
return openErr
}
defer db.Close()
defer func() {
_ = db.Close()
}()

helpers.LogDebug("Saving file...", "save model - bolt")
if err := db.Save(wl); err != nil {
Expand All @@ -87,7 +91,9 @@ func (*bboltRepo) GetAllBetweenDates(startDate, endDate time.Time, filter *model
helpers.LogError(fmt.Sprintf("Error opening file: %s", openErr.Error()), "read db error - bolt")
return nil, openErr
}
defer db.Close()
defer func() {
_ = db.Close()
}()

sel := q.And(
q.Gte("WhenQueryEpoch", startDate.Unix()),
Expand Down Expand Up @@ -119,7 +125,9 @@ func (*bboltRepo) GetByID(ID string, filter *model.Work) (*model.Work, error) {
helpers.LogError(fmt.Sprintf("Error opening file: %s", openErr.Error()), "read db error - bolt")
return nil, openErr
}
defer db.Close()
defer func() {
_ = db.Close()
}()

sel := q.And(
q.Re("ID", helpers.RegexCaseInsensitive+ID),
Expand All @@ -146,7 +154,9 @@ func (*bboltRepo) GetAll() ([]*model.Work, error) {
helpers.LogError(fmt.Sprintf("Error opening file: %s", openErr.Error()), "read db error - bolt")
return nil, openErr
}
defer db.Close()
defer func() {
_ = db.Close()
}()

err := db.All(&all)
return all, err
Expand Down
3 changes: 1 addition & 2 deletions repository/yamlFileRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package repository
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -281,7 +280,7 @@ func getFileByID(ID string) (string, error) {
}

func parseFileToWork(filePath string) (*model.Work, error) {
yamlFile, err := ioutil.ReadFile(filepath.Clean(filePath))
yamlFile, err := os.ReadFile(filepath.Clean(filePath))
if err != nil {
return nil, fmt.Errorf("%s %s. %e", e.RepoGetFilesRead, filePath, err)
}
Expand Down
4 changes: 3 additions & 1 deletion server/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func Create(resp http.ResponseWriter, req *http.Request) {
}
// #nosec CWE-703 -- From my understanding, IO errors can occur, which are potentially an issue during file IO.
// I haven't seen a similar example of harm to a network IO so will ignore for now.
defer req.Body.Close()
defer func() {
_ = req.Body.Close()
}()

wl := model.NewWork(
body.Title,
Expand Down
4 changes: 3 additions & 1 deletion server/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func Edit(resp http.ResponseWriter, req *http.Request) {
}
// #nosec CWE-703 -- From my understanding, IO errors can occur, which are potentially an issue during file IO.
// I haven't seen a similar example of harm to a network IO so will ignore for now.
defer req.Body.Close()
defer func() {
_ = req.Body.Close()
}()

newWl := model.NewWork(
body.Title,
Expand Down
7 changes: 2 additions & 5 deletions server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
httpRouter *mux.Router = mux.NewRouter().StrictSlash(true)
wlService service.WorklogService
wlRepo repository.WorklogRepository
wlConfig repository.ConfigRepository
)

var (
Expand Down Expand Up @@ -110,8 +109,8 @@ func interruptAndExit(server *http.Server) {
helpers.LogInfo("server stopping...", "shutdown")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
// #nosec G104 -- There could be an error while shutting down, but its during shutdown
server.Shutdown(ctx)

_ = server.Shutdown(ctx)
}

func InitCobra() {
Expand Down Expand Up @@ -175,7 +174,5 @@ func InitConfig() {
os.Exit(e.StartupErrors)
}

wlConfig = repository.NewYamlConfig(
filepath.Dir(cfgFile))
wlService = service.NewWorklogService(wlRepo)
}
6 changes: 3 additions & 3 deletions service/worklogService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package service
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -83,7 +83,7 @@ func (*service) GetWorklogsBetween(start, end time.Time, filter *model.Work) ([]
var worklogs model.WorkList
var err error

if (end == time.Time{}) {
if (end.Equal(time.Time{})) {
end = time.Date(3000, time.January, 1, 0, 0, 0, 0, time.Now().Location())
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func (*service) ExportTo(path string) (int, error) {
}
// #nosec G306 -- Not concerned that others on machine can access the exported values
// if the user wants to update permissions later, they can
err = ioutil.WriteFile(path, data, 0644)
err = os.WriteFile(path, data, 0644)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("error saving file. %s", err.Error())
}
Expand Down
Loading