Skip to content

Commit

Permalink
refactor: run the fetching of json from file once
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Mar 30, 2022
1 parent ed549af commit 9849a28
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions core/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import (
"flag"
"fmt"
"os"
"sync"
)

var (
payloadData []byte = []byte("")
doOnce sync.Once
)

type Arguments struct {
Expand Down Expand Up @@ -108,13 +114,13 @@ func (flags *Arguments) IsJSONPayload() bool {
}

func (flags *Arguments) JSONPayload() []byte {
if *flags.json != "" {
payload := FileContent(*flags.json)

return []byte(payload)
}
doOnce.Do(func() {
if *flags.json != "" {
payloadData = []byte(FileContent(*flags.json))
}
})

return []byte("")
return payloadData
}

func (flags *Arguments) Headers() []string {
Expand Down

0 comments on commit 9849a28

Please sign in to comment.