Skip to content

Commit

Permalink
📝 chore: all - update some comments and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 5, 2023
1 parent 133da19 commit 7747e31
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
13 changes: 3 additions & 10 deletions envutil/get.go
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"path/filepath"

"github.com/gookit/goutil/basefn"
"github.com/gookit/goutil/internal/comfunc"
"github.com/gookit/goutil/strutil"
)
Expand All @@ -22,23 +23,15 @@ func GetInt(name string, def ...int) int {
if val := os.Getenv(name); val != "" {
return strutil.QuietInt(val)
}

if len(def) > 0 {
return def[0]
}
return 0
return basefn.FirstOr(def, 0)
}

// GetBool get bool ENV value by key name, can with default value
func GetBool(name string, def ...bool) bool {
if val := os.Getenv(name); val != "" {
return strutil.QuietBool(val)
}

if len(def) > 0 {
return def[0]
}
return false
return basefn.FirstOr(def, false)
}

// GetMulti ENV values by input names.
Expand Down
4 changes: 2 additions & 2 deletions fsutil/finder/finder.go
Expand Up @@ -56,8 +56,8 @@ func EmptyFinder() *Finder { return NewEmpty() }
//
// Usage:
//
// f := NewFinder("/path/to/dir").Find()
// for el := range f {
// f := NewFinder("/path/to/dir")
// for el := range f.Find() {
// fmt.Println(el.Path())
// }
func (f *Finder) Find() <-chan Elem {
Expand Down
20 changes: 10 additions & 10 deletions testutil/httpmock_test.go
Expand Up @@ -65,18 +65,18 @@ func TestNewEchoServer(t *testing.T) {
r, err := http.Post(testSrvAddr, "text/plain", strings.NewReader("hello!"))
assert.NoErr(t, err)

rpl := testutil.ParseRespToReply(r)
dump.P(rpl)
assert.Eq(t, "POST", rpl.Method)
assert.Eq(t, "text/plain", rpl.ContentType())
assert.Eq(t, "hello!", rpl.Body)
rr := testutil.ParseRespToReply(r)
dump.P(rr)
assert.Eq(t, "POST", rr.Method)
assert.Eq(t, "text/plain", rr.ContentType())
assert.Eq(t, "hello!", rr.Body)

r, err = http.Post(testSrvAddr, "application/json", strings.NewReader(`{"name": "inhere", "age": 18}`))
assert.NoErr(t, err)

rpl = testutil.ParseRespToReply(r)
dump.P(rpl)
assert.Eq(t, "POST", rpl.Method)
assert.Eq(t, "application/json", rpl.ContentType())
assert.Eq(t, `{"name": "inhere", "age": 18}`, rpl.Body)
rr = testutil.ParseRespToReply(r)
dump.P(rr)
assert.Eq(t, "POST", rr.Method)
assert.Eq(t, "application/json", rr.ContentType())
assert.Eq(t, `{"name": "inhere", "age": 18}`, rr.Body)
}
4 changes: 2 additions & 2 deletions timex/util.go
Expand Up @@ -163,9 +163,9 @@ func ensureOpt(opt *ParseRangeOpt) *ParseRangeOpt {
// "-5h~-1h" => 5 hours ago to 1 hour ago
// "1h~5h" => 1 hour after to 5 hours after
// "-1h~1h" => 1 hour ago to 1 hour after
// "-1h" => 1 hour ago to feature. eq "-1h,"
// "-1h" => 1 hour ago to feature. eq "-1h~"
// "-1h~0" => 1 hour ago to now.
// "< -1h" OR "~-1h" => 1 hour ago. eq ",-1h"
// "< -1h" OR "~-1h" => 1 hour ago.
// "> 1h" OR "1h" => 1 hour after to feature
// // keyword: now, today, yesterday, tomorrow
// "today" => today start to today end
Expand Down

0 comments on commit 7747e31

Please sign in to comment.