-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moves a few dependencies internally to cut down on the number or exte…
…rnal (#399) deps
- Loading branch information
1 parent
6df815a
commit 05102f3
Showing
29 changed files
with
239 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package defaults | ||
|
||
func String(s1, s2 string) string { | ||
if s1 == "" { | ||
return s2 | ||
} | ||
return s1 | ||
} | ||
|
||
func Int(i1, i2 int) int { | ||
if i1 == 0 { | ||
return i2 | ||
} | ||
return i1 | ||
} | ||
|
||
func Int64(i1, i2 int64) int64 { | ||
if i1 == 0 { | ||
return i2 | ||
} | ||
return i1 | ||
} | ||
|
||
func Float32(i1, i2 float32) float32 { | ||
if i1 == 0.0 { | ||
return i2 | ||
} | ||
return i1 | ||
} | ||
|
||
func Float64(i1, i2 float64) float64 { | ||
if i1 == 0.0 { | ||
return i2 | ||
} | ||
return i1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package defaults | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_String(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal(String("", "foo"), "foo") | ||
a.Equal(String("bar", "foo"), "bar") | ||
var s string | ||
a.Equal(String(s, "foo"), "foo") | ||
} | ||
|
||
func Test_Int(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal(Int(0, 1), 1) | ||
a.Equal(Int(2, 1), 2) | ||
var s int | ||
a.Equal(Int(s, 1), 1) | ||
} | ||
|
||
func Test_Int64(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal(Int64(0, 1), int64(1)) | ||
a.Equal(Int64(2, 1), int64(2)) | ||
var s int64 | ||
a.Equal(Int64(s, 1), int64(1)) | ||
} | ||
|
||
func Test_Float32(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal(Float32(0, 1), float32(1)) | ||
a.Equal(Float32(2, 1), float32(2)) | ||
var s float32 | ||
a.Equal(Float32(s, 1), float32(1)) | ||
} | ||
|
||
func Test_Float64(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal(Float64(0, 1), float64(1)) | ||
a.Equal(Float64(2, 1), float64(2)) | ||
var s float64 | ||
a.Equal(Float64(s, 1), float64(1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package oncer | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
const deprecated = "DEPRECATED" | ||
|
||
var deprecationWriter io.Writer = os.Stdout | ||
|
||
func Deprecate(depth int, name string, msg string) { | ||
Do(deprecated+name, func() { | ||
fmt.Fprintf(deprecationWriter, "[%s] %s has been deprecated.\n", deprecated, name) | ||
if len(msg) > 0 { | ||
fmt.Fprintf(deprecationWriter, "\t%s\n", msg) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package oncer | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
var onces = &sync.Map{} | ||
|
||
func Do(name string, fn func()) { | ||
o, _ := onces.LoadOrStore(name, &sync.Once{}) | ||
if once, ok := o.(*sync.Once); ok { | ||
once.Do(fn) | ||
} | ||
} | ||
|
||
func Reset(names ...string) { | ||
if len(names) == 0 { | ||
onces = &sync.Map{} | ||
return | ||
} | ||
|
||
for _, n := range names { | ||
onces.Delete(n) | ||
onces.Delete(deprecated + n) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package randx | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package randx | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
// source https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go | ||
|
||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
const ( | ||
letterIdxBits = 6 // 6 bits to represent a letter index | ||
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits | ||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits | ||
) | ||
|
||
var src = rand.NewSource(time.Now().UnixNano()) | ||
|
||
func String(n int) string { | ||
b := make([]byte, n) | ||
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters! | ||
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { | ||
if remain == 0 { | ||
cache, remain = src.Int63(), letterIdxMax | ||
} | ||
if idx := int(cache & letterIdxMask); idx < len(letterBytes) { | ||
b[i] = letterBytes[idx] | ||
i-- | ||
} | ||
cache >>= letterIdxBits | ||
remain-- | ||
} | ||
|
||
return string(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package randx | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func init() { | ||
rand.Seed(1) | ||
} | ||
|
||
func Test_String(t *testing.T) { | ||
r := require.New(t) | ||
r.Len(String(5), 5) | ||
r.Len(String(50), 50) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.