forked from TrueCloudLab/rclone
vendor: update all dependencies
This commit is contained in:
parent
3f0789e2db
commit
08021c4636
2474 changed files with 435818 additions and 282709 deletions
2
vendor/github.com/pengsrc/go-shared/README.md
generated
vendored
2
vendor/github.com/pengsrc/go-shared/README.md
generated
vendored
|
@ -14,6 +14,6 @@ Useful packages for the Go programming language.
|
|||
4. Push to the branch (`git push origin new-feature`)
|
||||
5. Create a new Pull Request
|
||||
|
||||
## LICENSE
|
||||
## License
|
||||
|
||||
The Apache License (Version 2.0, January 2004).
|
||||
|
|
26
vendor/github.com/pengsrc/go-shared/convert/time.go
generated
vendored
26
vendor/github.com/pengsrc/go-shared/convert/time.go
generated
vendored
|
@ -49,12 +49,34 @@ func TimestampToTime(unix int64) time.Time {
|
|||
return time.Unix(unix, 0).UTC()
|
||||
}
|
||||
|
||||
// StringToUnixTimestamp transforms given string to unix time int64. It will
|
||||
// TimestampToTimePointer transforms given unix time int64 to time pointer in UTC.
|
||||
func TimestampToTimePointer(unix int64) *time.Time {
|
||||
if unix == 0 {
|
||||
return nil
|
||||
}
|
||||
t := time.Unix(unix, 0).UTC()
|
||||
return &t
|
||||
}
|
||||
|
||||
// TimePointerToTimestamp transforms given time pointer to unix time int64.
|
||||
func TimePointerToTimestamp(t *time.Time) int64 {
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
return t.Unix()
|
||||
}
|
||||
|
||||
// StringToTimestamp transforms given string to unix time int64. It will
|
||||
// return -1 when time string parse error.
|
||||
func StringToUnixTimestamp(timeString string, format string) int64 {
|
||||
func StringToTimestamp(timeString string, format string) int64 {
|
||||
t, err := StringToTime(timeString, format)
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return t.Unix()
|
||||
}
|
||||
|
||||
// TimestampToString converts unix timestamp to formatted string.
|
||||
func TimestampToString(unix int64, format string) string {
|
||||
return TimeToString(time.Unix(unix, 0).UTC(), format)
|
||||
}
|
||||
|
|
53
vendor/github.com/pengsrc/go-shared/convert/time_test.go
generated
vendored
53
vendor/github.com/pengsrc/go-shared/convert/time_test.go
generated
vendored
|
@ -51,17 +51,7 @@ func TestStringToTime(t *testing.T) {
|
|||
assert.Equal(t, someTime.UTC(), parsedTime.UTC())
|
||||
}
|
||||
|
||||
func TestStringToUnixString(t *testing.T) {
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("Thu, 01 Sep 2016 07:30:00 GMT", RFC822))
|
||||
assert.Equal(t, int64(-1), StringToUnixTimestamp("2016-09-01T07:30:00.000Z", RFC822))
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("2016-09-01T07:30:00Z", ISO8601))
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("2016-09-01T07:30:00.000Z", ISO8601Milli))
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("2016-09-01T07:30:00.500Z", ISO8601Milli))
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("01/Sep/2016:15:30:00 +0800", NGINXTime))
|
||||
assert.Equal(t, int64(1472715000), StringToUnixTimestamp("01/Sep/2016:07:30:00 +0000", NGINXTime))
|
||||
}
|
||||
|
||||
func TestTimeToUnixInt(t *testing.T) {
|
||||
func TestTimeToTimestamp(t *testing.T) {
|
||||
tz, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
someTime := time.Date(2016, 9, 1, 15, 30, 0, 0, tz)
|
||||
|
@ -69,10 +59,49 @@ func TestTimeToUnixInt(t *testing.T) {
|
|||
assert.Equal(t, int64(1472715000), TimeToTimestamp(someTime))
|
||||
}
|
||||
|
||||
func TestUnixIntToTime(t *testing.T) {
|
||||
func TestTimestampToTime(t *testing.T) {
|
||||
tz, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
someTime := time.Date(2016, 9, 1, 15, 30, 0, 0, tz)
|
||||
|
||||
assert.Equal(t, someTime.UTC(), TimestampToTime(1472715000))
|
||||
}
|
||||
|
||||
func TestTimestampToTimePointer(t *testing.T) {
|
||||
tz, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
someTime := time.Date(2016, 9, 1, 15, 30, 0, 0, tz).UTC()
|
||||
|
||||
assert.Equal(t, &someTime, TimestampToTimePointer(1472715000))
|
||||
assert.Nil(t, TimestampToTimePointer(0))
|
||||
}
|
||||
|
||||
func TestTimePointerToTimestamp(t *testing.T) {
|
||||
tz, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
unixTime := int64(1472715000)
|
||||
someTime := time.Date(2016, 9, 1, 15, 30, 0, 0, tz)
|
||||
|
||||
assert.Equal(t, unixTime, TimePointerToTimestamp(&someTime))
|
||||
assert.Equal(t, int64(0), TimePointerToTimestamp(nil))
|
||||
}
|
||||
|
||||
func TestStringToTimestamp(t *testing.T) {
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("Thu, 01 Sep 2016 07:30:00 GMT", RFC822))
|
||||
assert.Equal(t, int64(-1), StringToTimestamp("2016-09-01T07:30:00.000Z", RFC822))
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("2016-09-01T07:30:00Z", ISO8601))
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("2016-09-01T07:30:00.000Z", ISO8601Milli))
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("2016-09-01T07:30:00.500Z", ISO8601Milli))
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("01/Sep/2016:15:30:00 +0800", NGINXTime))
|
||||
assert.Equal(t, int64(1472715000), StringToTimestamp("01/Sep/2016:07:30:00 +0000", NGINXTime))
|
||||
}
|
||||
|
||||
func TestTimestampToString(t *testing.T) {
|
||||
assert.Equal(t, StringToTimestamp("Thu, 01 Sep 2016 07:30:00 GMT", RFC822), int64(1472715000))
|
||||
assert.Equal(t, StringToTimestamp("2016-09-01T07:30:00.000Z", RFC822), int64(-1))
|
||||
assert.Equal(t, StringToTimestamp("2016-09-01T07:30:00Z", ISO8601), int64(1472715000))
|
||||
assert.Equal(t, StringToTimestamp("2016-09-01T07:30:00.000Z", ISO8601Milli), int64(1472715000))
|
||||
assert.Equal(t, StringToTimestamp("2016-09-01T07:30:00.500Z", ISO8601Milli), int64(1472715000))
|
||||
assert.Equal(t, StringToTimestamp("01/Sep/2016:15:30:00 +0800", NGINXTime), int64(1472715000))
|
||||
assert.Equal(t, StringToTimestamp("01/Sep/2016:07:30:00 +0000", NGINXTime), int64(1472715000))
|
||||
}
|
||||
|
|
68
vendor/github.com/pengsrc/go-shared/convert/types.go
generated
vendored
68
vendor/github.com/pengsrc/go-shared/convert/types.go
generated
vendored
|
@ -19,7 +19,7 @@ func StringValue(v *string) string {
|
|||
}
|
||||
|
||||
// StringSlice converts a slice of string values into a slice of
|
||||
// string pointers
|
||||
// string pointers.
|
||||
func StringSlice(src []string) []*string {
|
||||
dst := make([]*string, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -29,7 +29,7 @@ func StringSlice(src []string) []*string {
|
|||
}
|
||||
|
||||
// StringValueSlice converts a slice of string pointers into a slice of
|
||||
// string values
|
||||
// string values.
|
||||
func StringValueSlice(src []*string) []string {
|
||||
dst := make([]string, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -41,7 +41,7 @@ func StringValueSlice(src []*string) []string {
|
|||
}
|
||||
|
||||
// StringMap converts a string map of string values into a string
|
||||
// map of string pointers
|
||||
// map of string pointers.
|
||||
func StringMap(src map[string]string) map[string]*string {
|
||||
dst := make(map[string]*string)
|
||||
for k, val := range src {
|
||||
|
@ -52,7 +52,7 @@ func StringMap(src map[string]string) map[string]*string {
|
|||
}
|
||||
|
||||
// StringValueMap converts a string map of string pointers into a string
|
||||
// map of string values
|
||||
// map of string values.
|
||||
func StringValueMap(src map[string]*string) map[string]string {
|
||||
dst := make(map[string]string)
|
||||
for k, val := range src {
|
||||
|
@ -78,7 +78,7 @@ func BoolValue(v *bool) bool {
|
|||
}
|
||||
|
||||
// BoolSlice converts a slice of bool values into a slice of
|
||||
// bool pointers
|
||||
// bool pointers.
|
||||
func BoolSlice(src []bool) []*bool {
|
||||
dst := make([]*bool, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -88,7 +88,7 @@ func BoolSlice(src []bool) []*bool {
|
|||
}
|
||||
|
||||
// BoolValueSlice converts a slice of bool pointers into a slice of
|
||||
// bool values
|
||||
// bool values.
|
||||
func BoolValueSlice(src []*bool) []bool {
|
||||
dst := make([]bool, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -100,7 +100,7 @@ func BoolValueSlice(src []*bool) []bool {
|
|||
}
|
||||
|
||||
// BoolMap converts a string map of bool values into a string
|
||||
// map of bool pointers
|
||||
// map of bool pointers.
|
||||
func BoolMap(src map[string]bool) map[string]*bool {
|
||||
dst := make(map[string]*bool)
|
||||
for k, val := range src {
|
||||
|
@ -111,7 +111,7 @@ func BoolMap(src map[string]bool) map[string]*bool {
|
|||
}
|
||||
|
||||
// BoolValueMap converts a string map of bool pointers into a string
|
||||
// map of bool values
|
||||
// map of bool values.
|
||||
func BoolValueMap(src map[string]*bool) map[string]bool {
|
||||
dst := make(map[string]bool)
|
||||
for k, val := range src {
|
||||
|
@ -137,7 +137,7 @@ func IntValue(v *int) int {
|
|||
}
|
||||
|
||||
// IntSlice converts a slice of int values into a slice of
|
||||
// int pointers
|
||||
// int pointers.
|
||||
func IntSlice(src []int) []*int {
|
||||
dst := make([]*int, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -147,7 +147,7 @@ func IntSlice(src []int) []*int {
|
|||
}
|
||||
|
||||
// IntValueSlice converts a slice of int pointers into a slice of
|
||||
// int values
|
||||
// int values.
|
||||
func IntValueSlice(src []*int) []int {
|
||||
dst := make([]int, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -159,7 +159,7 @@ func IntValueSlice(src []*int) []int {
|
|||
}
|
||||
|
||||
// IntMap converts a string map of int values into a string
|
||||
// map of int pointers
|
||||
// map of int pointers.
|
||||
func IntMap(src map[string]int) map[string]*int {
|
||||
dst := make(map[string]*int)
|
||||
for k, val := range src {
|
||||
|
@ -170,7 +170,7 @@ func IntMap(src map[string]int) map[string]*int {
|
|||
}
|
||||
|
||||
// IntValueMap converts a string map of int pointers into a string
|
||||
// map of int values
|
||||
// map of int values.
|
||||
func IntValueMap(src map[string]*int) map[string]int {
|
||||
dst := make(map[string]int)
|
||||
for k, val := range src {
|
||||
|
@ -196,7 +196,7 @@ func Int32Value(v *int32) int32 {
|
|||
}
|
||||
|
||||
// Int32Slice converts a slice of int32 values into a slice of
|
||||
// int32 pointers
|
||||
// int32 pointers.
|
||||
func Int32Slice(src []int32) []*int32 {
|
||||
dst := make([]*int32, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -206,7 +206,7 @@ func Int32Slice(src []int32) []*int32 {
|
|||
}
|
||||
|
||||
// Int32ValueSlice converts a slice of int32 pointers into a slice of
|
||||
// int32 values
|
||||
// int32 values.
|
||||
func Int32ValueSlice(src []*int32) []int32 {
|
||||
dst := make([]int32, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -218,7 +218,7 @@ func Int32ValueSlice(src []*int32) []int32 {
|
|||
}
|
||||
|
||||
// Int32Map converts a string map of int32 values into a string
|
||||
// map of int32 pointers
|
||||
// map of int32 pointers.
|
||||
func Int32Map(src map[string]int32) map[string]*int32 {
|
||||
dst := make(map[string]*int32)
|
||||
for k, val := range src {
|
||||
|
@ -229,7 +229,7 @@ func Int32Map(src map[string]int32) map[string]*int32 {
|
|||
}
|
||||
|
||||
// Int32ValueMap converts a string map of int32 pointers into a string
|
||||
// map of int32 values
|
||||
// map of int32 values.
|
||||
func Int32ValueMap(src map[string]*int32) map[string]int32 {
|
||||
dst := make(map[string]int32)
|
||||
for k, val := range src {
|
||||
|
@ -255,7 +255,7 @@ func Int64Value(v *int64) int64 {
|
|||
}
|
||||
|
||||
// Int64Slice converts a slice of int64 values into a slice of
|
||||
// int64 pointers
|
||||
// int64 pointers.
|
||||
func Int64Slice(src []int64) []*int64 {
|
||||
dst := make([]*int64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -265,7 +265,7 @@ func Int64Slice(src []int64) []*int64 {
|
|||
}
|
||||
|
||||
// Int64ValueSlice converts a slice of int64 pointers into a slice of
|
||||
// int64 values
|
||||
// int64 values.
|
||||
func Int64ValueSlice(src []*int64) []int64 {
|
||||
dst := make([]int64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -277,7 +277,7 @@ func Int64ValueSlice(src []*int64) []int64 {
|
|||
}
|
||||
|
||||
// Int64Map converts a string map of int64 values into a string
|
||||
// map of int64 pointers
|
||||
// map of int64 pointers.
|
||||
func Int64Map(src map[string]int64) map[string]*int64 {
|
||||
dst := make(map[string]*int64)
|
||||
for k, val := range src {
|
||||
|
@ -288,7 +288,7 @@ func Int64Map(src map[string]int64) map[string]*int64 {
|
|||
}
|
||||
|
||||
// Int64ValueMap converts a string map of int64 pointers into a string
|
||||
// map of int64 values
|
||||
// map of int64 values.
|
||||
func Int64ValueMap(src map[string]*int64) map[string]int64 {
|
||||
dst := make(map[string]int64)
|
||||
for k, val := range src {
|
||||
|
@ -351,7 +351,7 @@ func Uint64Value(v *uint64) uint64 {
|
|||
}
|
||||
|
||||
// Uint64Slice converts a slice of uint64 values into a slice of
|
||||
// uint64 pointers
|
||||
// uint64 pointers.
|
||||
func Uint64Slice(src []uint64) []*uint64 {
|
||||
dst := make([]*uint64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -361,7 +361,7 @@ func Uint64Slice(src []uint64) []*uint64 {
|
|||
}
|
||||
|
||||
// Uint64ValueSlice converts a slice of uint64 pointers into a slice of
|
||||
// uint64 values
|
||||
// uint64 values.
|
||||
func Uint64ValueSlice(src []*uint64) []uint64 {
|
||||
dst := make([]uint64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -387,7 +387,7 @@ func Float32Value(v *float32) float32 {
|
|||
}
|
||||
|
||||
// Float32Slice converts a slice of float32 values into a slice of
|
||||
// float32 pointers
|
||||
// float32 pointers.
|
||||
func Float32Slice(src []float32) []*float32 {
|
||||
dst := make([]*float32, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -397,7 +397,7 @@ func Float32Slice(src []float32) []*float32 {
|
|||
}
|
||||
|
||||
// Float32ValueSlice converts a slice of float32 pointers into a slice of
|
||||
// float32 values
|
||||
// float32 values.
|
||||
func Float32ValueSlice(src []*float32) []float32 {
|
||||
dst := make([]float32, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -409,7 +409,7 @@ func Float32ValueSlice(src []*float32) []float32 {
|
|||
}
|
||||
|
||||
// Float32Map converts a string map of float32 values into a string
|
||||
// map of float32 pointers
|
||||
// map of float32 pointers.
|
||||
func Float32Map(src map[string]float32) map[string]*float32 {
|
||||
dst := make(map[string]*float32)
|
||||
for k, val := range src {
|
||||
|
@ -420,7 +420,7 @@ func Float32Map(src map[string]float32) map[string]*float32 {
|
|||
}
|
||||
|
||||
// Float32ValueMap converts a string map of float32 pointers into a string
|
||||
// map of float32 values
|
||||
// map of float32 values.
|
||||
func Float32ValueMap(src map[string]*float32) map[string]float32 {
|
||||
dst := make(map[string]float32)
|
||||
for k, val := range src {
|
||||
|
@ -446,7 +446,7 @@ func Float64Value(v *float64) float64 {
|
|||
}
|
||||
|
||||
// Float64Slice converts a slice of float64 values into a slice of
|
||||
// float64 pointers
|
||||
// float64 pointers.
|
||||
func Float64Slice(src []float64) []*float64 {
|
||||
dst := make([]*float64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -456,7 +456,7 @@ func Float64Slice(src []float64) []*float64 {
|
|||
}
|
||||
|
||||
// Float64ValueSlice converts a slice of float64 pointers into a slice of
|
||||
// float64 values
|
||||
// float64 values.
|
||||
func Float64ValueSlice(src []*float64) []float64 {
|
||||
dst := make([]float64, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -468,7 +468,7 @@ func Float64ValueSlice(src []*float64) []float64 {
|
|||
}
|
||||
|
||||
// Float64Map converts a string map of float64 values into a string
|
||||
// map of float64 pointers
|
||||
// map of float64 pointers.
|
||||
func Float64Map(src map[string]float64) map[string]*float64 {
|
||||
dst := make(map[string]*float64)
|
||||
for k, val := range src {
|
||||
|
@ -479,7 +479,7 @@ func Float64Map(src map[string]float64) map[string]*float64 {
|
|||
}
|
||||
|
||||
// Float64ValueMap converts a string map of float64 pointers into a string
|
||||
// map of float64 values
|
||||
// map of float64 values.
|
||||
func Float64ValueMap(src map[string]*float64) map[string]float64 {
|
||||
dst := make(map[string]float64)
|
||||
for k, val := range src {
|
||||
|
@ -505,7 +505,7 @@ func TimeValue(v *time.Time) time.Time {
|
|||
}
|
||||
|
||||
// TimeSlice converts a slice of time.Time values into a slice of
|
||||
// time.Time pointers
|
||||
// time.Time pointers.
|
||||
func TimeSlice(src []time.Time) []*time.Time {
|
||||
dst := make([]*time.Time, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -515,7 +515,7 @@ func TimeSlice(src []time.Time) []*time.Time {
|
|||
}
|
||||
|
||||
// TimeValueSlice converts a slice of time.Time pointers into a slice of
|
||||
// time.Time values
|
||||
// time.Time values.
|
||||
func TimeValueSlice(src []*time.Time) []time.Time {
|
||||
dst := make([]time.Time, len(src))
|
||||
for i := 0; i < len(src); i++ {
|
||||
|
@ -527,7 +527,7 @@ func TimeValueSlice(src []*time.Time) []time.Time {
|
|||
}
|
||||
|
||||
// TimeMap converts a string map of time.Time values into a string
|
||||
// map of time.Time pointers
|
||||
// map of time.Time pointers.
|
||||
func TimeMap(src map[string]time.Time) map[string]*time.Time {
|
||||
dst := make(map[string]*time.Time)
|
||||
for k, val := range src {
|
||||
|
@ -538,7 +538,7 @@ func TimeMap(src map[string]time.Time) map[string]*time.Time {
|
|||
}
|
||||
|
||||
// TimeValueMap converts a string map of time.Time pointers into a string
|
||||
// map of time.Time values
|
||||
// map of time.Time values.
|
||||
func TimeValueMap(src map[string]*time.Time) map[string]time.Time {
|
||||
dst := make(map[string]time.Time)
|
||||
for k, val := range src {
|
||||
|
|
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