Update split SDK to 6.0.2 to fix sync bug (#17060)
* Update split SDK to 6.0.2 to fix sync bug * Vendor and tidy
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fa2ecad0a9
Коммит
aba00a3cfd
53
vendor/github.com/splitio/go-toolkit/v4/common/interface.go
сгенерированный
поставляемый
Обычный файл
53
vendor/github.com/splitio/go-toolkit/v4/common/interface.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,53 @@
|
||||
package common
|
||||
|
||||
// AsIntOrNil returns ref
|
||||
func AsIntOrNil(data interface{}) *int {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
number, ok := data.(int)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return IntRef(number)
|
||||
}
|
||||
|
||||
// AsInt64OrNil returns ref
|
||||
func AsInt64OrNil(data interface{}) *int64 {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
number, ok := data.(int64)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return Int64Ref(number)
|
||||
}
|
||||
|
||||
// AsFloat64OrNil return ref
|
||||
func AsFloat64OrNil(data interface{}) *float64 {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
number, ok := data.(float64)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return Float64Ref(number)
|
||||
}
|
||||
|
||||
// AsStringOrNil returns ref
|
||||
func AsStringOrNil(data interface{}) *string {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, ok := data.(string)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return StringRef(str)
|
||||
}
|
||||
67
vendor/github.com/splitio/go-toolkit/v4/common/iterutil.go
сгенерированный
поставляемый
Обычный файл
67
vendor/github.com/splitio/go-toolkit/v4/common/iterutil.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,67 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// WithAttempts executes a function N times or until no error is returned
|
||||
func WithAttempts(attempts int, main func() error) error {
|
||||
err := errors.New("")
|
||||
remaining := attempts
|
||||
for err != nil && remaining > 0 {
|
||||
remaining--
|
||||
err = main()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// WithBackoff wraps the function to add Exponential backoff
|
||||
func WithBackoff(duration time.Duration, main func() error) func() error {
|
||||
var count time.Duration = 1
|
||||
return func() error {
|
||||
err := main()
|
||||
if err != nil {
|
||||
time.Sleep(count * duration)
|
||||
count++
|
||||
} else {
|
||||
count = 0
|
||||
}
|
||||
return main()
|
||||
}
|
||||
}
|
||||
|
||||
// WithBackoffCancelling wraps the function to add Exponential backoff
|
||||
func WithBackoffCancelling(unit time.Duration, max time.Duration, main func() bool) func() {
|
||||
cancel := make(chan struct{})
|
||||
go func() {
|
||||
attempts := 0
|
||||
isDone := main()
|
||||
|
||||
// Create timeout timer for backoff
|
||||
backoffTimer := time.NewTimer(MinDuration(time.Duration(math.Pow(2, float64(attempts)))*unit, max))
|
||||
defer backoffTimer.Stop()
|
||||
|
||||
for !isDone {
|
||||
attempts++
|
||||
|
||||
// Setting timer considerint attempts
|
||||
backoffTimer.Reset(MinDuration(time.Duration(math.Pow(2, float64(attempts)))*unit, max))
|
||||
|
||||
select {
|
||||
case <-cancel:
|
||||
return
|
||||
case <-backoffTimer.C: // Timedout
|
||||
isDone = main()
|
||||
}
|
||||
}
|
||||
}()
|
||||
return func() {
|
||||
select {
|
||||
case cancel <- struct{}{}:
|
||||
return
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
74
vendor/github.com/splitio/go-toolkit/v4/common/refutil.go
сгенерированный
поставляемый
Обычный файл
74
vendor/github.com/splitio/go-toolkit/v4/common/refutil.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,74 @@
|
||||
package common
|
||||
|
||||
// StringRef returns ref
|
||||
func StringRef(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
// StringFromRef returns original value if not empty. Default otherwise.
|
||||
func StringFromRef(str *string) string {
|
||||
if str == nil {
|
||||
return ""
|
||||
}
|
||||
return *str
|
||||
}
|
||||
|
||||
// IntRef returns ref
|
||||
func IntRef(number int) *int {
|
||||
return &number
|
||||
}
|
||||
|
||||
// IntFromRef returns 0 if nil, dereferenced value otherwhise.
|
||||
func IntFromRef(ref *int) int {
|
||||
if ref == nil {
|
||||
return 0
|
||||
}
|
||||
return *ref
|
||||
}
|
||||
|
||||
// Int64Ref returns ref
|
||||
func Int64Ref(number int64) *int64 {
|
||||
return &number
|
||||
}
|
||||
|
||||
// Int64FromRef returns value
|
||||
func Int64FromRef(number *int64) int64 {
|
||||
if number == nil {
|
||||
return 0
|
||||
}
|
||||
return *number
|
||||
}
|
||||
|
||||
// Int64Value kept to prevent breaking change. TODO: Deprecate in v4
|
||||
func Int64Value(number *int64) int64 {
|
||||
return Int64FromRef(number)
|
||||
}
|
||||
|
||||
// Float64Ref returns ref
|
||||
func Float64Ref(number float64) *float64 {
|
||||
return &number
|
||||
}
|
||||
|
||||
// IntRefOrNil returns ref
|
||||
func IntRefOrNil(number int) *int {
|
||||
if number == 0 {
|
||||
return nil
|
||||
}
|
||||
return IntRef(number)
|
||||
}
|
||||
|
||||
// Int64RefOrNil returns ref
|
||||
func Int64RefOrNil(number int64) *int64 {
|
||||
if number == 0 {
|
||||
return nil
|
||||
}
|
||||
return Int64Ref(number)
|
||||
}
|
||||
|
||||
// StringRefOrNil returns ref
|
||||
func StringRefOrNil(str string) *string {
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
return StringRef(str)
|
||||
}
|
||||
18
vendor/github.com/splitio/go-toolkit/v4/common/sliceutil.go
сгенерированный
поставляемый
Обычный файл
18
vendor/github.com/splitio/go-toolkit/v4/common/sliceutil.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,18 @@
|
||||
package common
|
||||
|
||||
// Partition create partitions considering the passed amount
|
||||
func Partition(items []string, maxItems int) [][]string {
|
||||
var splitted [][]string
|
||||
|
||||
for i := 0; i < len(items); i += maxItems {
|
||||
end := i + maxItems
|
||||
|
||||
if end > len(items) {
|
||||
end = len(items)
|
||||
}
|
||||
|
||||
splitted = append(splitted, items[i:end])
|
||||
}
|
||||
|
||||
return splitted
|
||||
}
|
||||
9
vendor/github.com/splitio/go-toolkit/v4/common/strutil.go
сгенерированный
поставляемый
Обычный файл
9
vendor/github.com/splitio/go-toolkit/v4/common/strutil.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,9 @@
|
||||
package common
|
||||
|
||||
// StringValueOrDefault returns original value if not empty. Default otherwise.
|
||||
func StringValueOrDefault(str string, def string) string {
|
||||
if str != "" {
|
||||
return str
|
||||
}
|
||||
return def
|
||||
}
|
||||
25
vendor/github.com/splitio/go-toolkit/v4/common/timeutil.go
сгенерированный
поставляемый
Обычный файл
25
vendor/github.com/splitio/go-toolkit/v4/common/timeutil.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,25 @@
|
||||
package common
|
||||
|
||||
import "time"
|
||||
|
||||
// MinDuration returns the min duration among them
|
||||
func MinDuration(d1, d2 time.Duration, ds ...time.Duration) time.Duration {
|
||||
min := d1
|
||||
for _, d := range append(ds, d2) {
|
||||
if d < min {
|
||||
min = d
|
||||
}
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
// MaxDuration returns the max duration among them
|
||||
func MaxDuration(d1, d2 time.Duration, ds ...time.Duration) time.Duration {
|
||||
max := d1
|
||||
for _, d := range append(ds, d2) {
|
||||
if d > max {
|
||||
max = d
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
Ссылка в новой задаче
Block a user