vendor: update all dependencies
This commit is contained in:
parent
3f0789e2db
commit
08021c4636
2474 changed files with 435818 additions and 282709 deletions
4
vendor/github.com/pengsrc/go-shared/utils/context.go
generated
vendored
Normal file
4
vendor/github.com/pengsrc/go-shared/utils/context.go
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
package utils
|
||||
|
||||
// ContextKey is the type that used for saving and restoring value in context.
|
||||
type ContextKey string
|
13
vendor/github.com/pengsrc/go-shared/utils/context_test.go
generated
vendored
Normal file
13
vendor/github.com/pengsrc/go-shared/utils/context_test.go
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestContextKey(t *testing.T) {
|
||||
var value ContextKey = "Hello world."
|
||||
|
||||
assert.Equal(t, "Hello world.", string(value))
|
||||
}
|
17
vendor/github.com/pengsrc/go-shared/utils/home.go
generated
vendored
Normal file
17
vendor/github.com/pengsrc/go-shared/utils/home.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// GetHome returns the home directory.
|
||||
func GetHome() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||
if home == "" {
|
||||
home = os.Getenv("USERPROFILE")
|
||||
}
|
||||
}
|
||||
return os.Getenv("HOME")
|
||||
}
|
15
vendor/github.com/pengsrc/go-shared/utils/home_test.go
generated
vendored
Normal file
15
vendor/github.com/pengsrc/go-shared/utils/home_test.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetHome(t *testing.T) {
|
||||
usr, err := user.Current()
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, usr.HomeDir, GetHome())
|
||||
}
|
16
vendor/github.com/pengsrc/go-shared/utils/recover.go
generated
vendored
Normal file
16
vendor/github.com/pengsrc/go-shared/utils/recover.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/pengsrc/go-shared/log"
|
||||
)
|
||||
|
||||
// Recover is a utils that recovers from panics, logs the panic (and a
|
||||
// backtrace) for functions in goroutine.
|
||||
func Recover(ctx context.Context) {
|
||||
if x := recover(); x != nil {
|
||||
log.Errorf(ctx, "Caught panic: %v, Trace: %s", x, debug.Stack())
|
||||
}
|
||||
}
|
31
vendor/github.com/pengsrc/go-shared/utils/recover_test.go
generated
vendored
Normal file
31
vendor/github.com/pengsrc/go-shared/utils/recover_test.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/pengsrc/go-shared/log"
|
||||
)
|
||||
|
||||
func TestRecover(t *testing.T) {
|
||||
discardLogger, err := log.NewLogger(ioutil.Discard)
|
||||
assert.NoError(t, err)
|
||||
log.SetGlobalLogger(discardLogger)
|
||||
defer log.SetGlobalLogger(nil)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer Recover(ctx)
|
||||
wg.Done()
|
||||
panic("fear")
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue