Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 17, 2023
1 parent 4c5ea83 commit d4b4dbd
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion action/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Wait(action *recipe.Action) error {
return err
}

durSec = mathutil.BetweenF64(durSec, 0.01, 3600.0)
durSec = mathutil.Between(durSec, 0.01, 3600.0)

time.Sleep(timeutil.SecondsToDuration(durSec))

Expand Down
2 changes: 1 addition & 1 deletion action/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func Cleanup(action *recipe.Action) error {
err = os.RemoveAll(obj)

if err != nil {
return fmt.Errorf("Can't remove object %q: %v", err)
return fmt.Errorf("Can't remove object %q: %v", obj, err)
}
}

Expand Down
13 changes: 2 additions & 11 deletions action/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,7 @@ func HTTPSetHeader(action *recipe.Action) error {

// ////////////////////////////////////////////////////////////////////////////////// //

// isHTTPMethodSupported returns true if HTTP method is supported
func isHTTPMethodSupported(method string) bool {
switch method {
case req.GET, req.POST, req.DELETE, req.PUT, req.PATCH, req.HEAD:
return true
}

return false
}

// checkRequestData checks request data
func checkRequestData(method, payload string) error {
switch method {
case req.GET, req.POST, req.DELETE, req.PUT, req.PATCH, req.HEAD:
Expand Down Expand Up @@ -353,6 +344,6 @@ func makeHTTPRequest(action *recipe.Action, method, url, payload string) *req.Re

// parseJSONQuery converts json query to slice
func parseJSONQuery(q string) []string {
q = strings.Replace(q, "[", ".[", -1)
q = strings.ReplaceAll(q, "[", ".[")
return strings.Split(q, ".")
}
4 changes: 2 additions & 2 deletions action/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Expect(action *recipe.Action, output *OutputContainer) error {
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(_DATA_READ_PERIOD).C {
Expand Down Expand Up @@ -98,7 +98,7 @@ func Input(action *recipe.Action, input *os.File, output *OutputContainer) error
}

if !strings.HasSuffix(text, "\n") {
text = text + "\n"
text += "\n"
}

output.Purge()
Expand Down
2 changes: 1 addition & 1 deletion action/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func WaitService(action *recipe.Action) error {
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(time.Second / 2).C {
Expand Down
8 changes: 4 additions & 4 deletions action/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func WaitPID(action *recipe.Action) error {
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(25 * time.Millisecond).C {
Expand Down Expand Up @@ -147,7 +147,7 @@ func WaitFS(action *recipe.Action) error {
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(25 * time.Millisecond).C {
Expand Down Expand Up @@ -203,7 +203,7 @@ func WaitConnect(action *recipe.Action) error {
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(25 * time.Millisecond).C {
Expand Down Expand Up @@ -264,7 +264,7 @@ func Connect(action *recipe.Action) error {
timeout = 1.0
}

timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeout = mathutil.Between(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

conn, err := net.DialTimeout(network, address, timeoutDur)
Expand Down
6 changes: 3 additions & 3 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "bibop", "recipe"))
fmt.Print(bash.Generate(info, "bibop", "recipe"))
case "fish":
fmt.Printf(fish.Generate(info, "bibop"))
fmt.Print(fish.Generate(info, "bibop"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "bibop", "*.recipe"))
fmt.Print(zsh.Generate(info, optMap, "bibop", "*.recipe"))
default:
return 1
}
Expand Down
2 changes: 1 addition & 1 deletion cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func getHashColorBullet(v string) string {

// printInfo formats and prints info record
func printInfo(size int, name, value string) {
name = name + ":"
name += ":"
size++

if value == "" {
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func getTokenInfo(keyword string) recipe.TokenInfo {
// isUselessRecipeLine return if line doesn't contains recipe data
func isUselessRecipeLine(line string) bool {
// Skip empty lines
if line == "" || strings.Replace(line, " ", "", -1) == "" {
if line == "" || strings.ReplaceAll(line, " ", "") == "" {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion render/renderer_terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (rr *TerminalRenderer) Result(passes, fails, skips int) {
}

d := rr.formatDuration(time.Since(rr.start), true)
d = strings.Replace(d, ".", "{s-}.", -1) + "{!}"
d = strings.ReplaceAll(d, ".", "{s-}.") + "{!}"

fmtc.NewLine()
fmtc.Println(" {*}Duration:{!} " + d)
Expand Down
6 changes: 3 additions & 3 deletions render/renderer_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func (rr *XMLRenderer) Result(passes, fails, skips int) {
// ////////////////////////////////////////////////////////////////////////////////// //

func (rr *XMLRenderer) escapeData(data string) string {
data = strings.Replace(data, "<", "&lt;", -1)
data = strings.Replace(data, ">", "&gt;", -1)
data = strings.Replace(data, "&", "&amp;", -1)
data = strings.ReplaceAll(data, "<", "&lt;")
data = strings.ReplaceAll(data, ">", "&gt;")
data = strings.ReplaceAll(data, "&", "&amp;")

return data
}
Expand Down

0 comments on commit d4b4dbd

Please sign in to comment.