Skip to content

Commit

Permalink
some lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Jan 8, 2022
1 parent 60ed197 commit 83a304a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 79 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![GitHub releases](https://img.shields.io/github/tag/howeyc/ledger.svg)](https://github.com/howeyc/ledger/releases)
[![GitHub downloads](https://img.shields.io/github/downloads/howeyc/ledger/total.svg?logo=github&logoColor=lime)](https://github.com/howeyc/ledger/releases)
[![Chat on Libera](https://img.shields.io/badge/chat-libera-blue.svg)](https://matrix.to/#/#plaintextaccounting:libera.chat)
[![Go Report Card](https://goreportcard.com/badge/github.com/howeyc/ledger)](https://goreportcard.com/report/github.com/howeyc/ledger)

# Ledger in Go

Expand Down
2 changes: 1 addition & 1 deletion ledger/cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func cliTransactions() ([]*ledger.Transaction, error) {
parsedEndDate, tendErr := time.Parse(transactionDateFormat, endString)

if tstartErr != nil || tendErr != nil {
return nil, errors.New("Unable to parse start or end date string argument.")
return nil, errors.New("unable to parse start or end date string argument")
}

var lreader io.Reader
Expand Down
4 changes: 2 additions & 2 deletions ledger/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ var statsCmd = &cobra.Command{
if terr != nil {
log.Fatalln(terr)
}
PrintStats(transactions)
printStats(transactions)
},
}

func PrintStats(generalLedger []*ledger.Transaction) {
func printStats(generalLedger []*ledger.Transaction) {
if len(generalLedger) < 1 {
fmt.Println("Empty ledger.")
return
Expand Down
24 changes: 11 additions & 13 deletions ledger/cmd/webHandlerAccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,26 @@ func addTransactionPostHandler(w http.ResponseWriter, r *http.Request, _ httprou
fmt.Fprintln(&tbuf, "")

/* Check valid transaction is created */
if trans, perr := ledger.ParseLedger(&tbuf); perr != nil {
trans, perr := ledger.ParseLedger(&tbuf)
if perr != nil {
http.Error(w, perr.Error(), 500)
return
} else {
f, err := os.OpenFile(ledgerFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
http.Error(w, err.Error(), 500)
return
}

for _, t := range trans {
WriteTransaction(f, t, 80)
}
}

f.Close()
f, err := os.OpenFile(ledgerFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
for _, t := range trans {
WriteTransaction(f, t, 80)
}
f.Close()

if _, err := getTransactions(); err != nil {
http.Error(w, err.Error(), 500)
return
}

fmt.Fprintf(w, "Transaction added!")
}

Expand Down
5 changes: 3 additions & 2 deletions ledgerReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (

var includedFiles = make(map[string]bool)

// NewLedgerReader reads a file and includes any files with include directives
// and returns the whole combined ledger as a buffer for parsing.
func NewLedgerReader(filename string) (*bytes.Buffer, error) {
var buf bytes.Buffer

Expand All @@ -36,9 +38,8 @@ func includeFile(filename string, buf *bytes.Buffer) error {
// check for include cyles
if includedFiles[filename] {
return fmt.Errorf("include cycle: '%s'", filename)
} else {
includedFiles[filename] = true
}
includedFiles[filename] = true

defer delete(includedFiles, filename)

Expand Down
Loading

0 comments on commit 83a304a

Please sign in to comment.