Skip to content

Commit

Permalink
Merge pull request #806 from MichaelMure/fix-mem-usage
Browse files Browse the repository at this point in the history
Fix: api: replace two regexes with strings.HasPrefix()
  • Loading branch information
lanzafame committed Jun 5, 2019
2 parents 35860d3 + 5515bdd commit a5a44b4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions api/types.go
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/json"
"fmt"
"net/url"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -191,14 +190,13 @@ type IPFSPinStatus int
// IPFSPinStatusFromString parses a string and returns the matching
// IPFSPinStatus.
func IPFSPinStatusFromString(t string) IPFSPinStatus {
// Since indirect statuses are of the form "indirect through <cid>",
// use a regexp to match
var ind, _ = regexp.MatchString("^indirect", t)
var rec, _ = regexp.MatchString("^recursive", t)
// Since indirect statuses are of the form "indirect through <cid>"
// use a prefix match

switch {
case ind:
case strings.HasPrefix(t, "indirect"):
return IPFSPinStatusIndirect
case rec:
case strings.HasPrefix(t, "recursive"):
// FIXME: Maxdepth?
return IPFSPinStatusRecursive
case t == "direct":
Expand Down

0 comments on commit a5a44b4

Please sign in to comment.