mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-18 23:27:55 +00:00
This will
Add:
- golang.org/x/time
upgrade:
- k8s.io/client-go v8.0.0
- k8s.io/api version to kubernetes-1.11.0
- k8s.io/apimachinery version to kubernetes-1.11.0
- github.com/json-iterator/go version to latest because `https://github.com/kubernetes/kubernetes/issues/64612`
delete:
- vendor/github.com/juju/ratelimit because k8s-client-go is shifted to golang.org/x/time
Please refer: acc52496ce
```
gvt delete k8s.io/client-go
gvt delete k8s.io/api
gvt delete k8s.io/apimachinery
gvt delete github.com/json-iterator/go
gvt delete github.com/juju/ratelimit
gvt fetch --no-recurse -tag v8.0.0 k8s.io/client-go
gvt fetch --no-recurse -tag kubernetes-1.11.0 k8s.io/api
gvt fetch --no-recurse -tag kubernetes-1.11.0 k8s.io/apimachinery
gvt fetch github.com/json-iterator/go
gvt fetch golang.org/x/time
```
fixes: #3284
Signed-off-by: Satyam Zode <satyamzode@gmail.com>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package extra
|
|
|
|
import (
|
|
"github.com/json-iterator/go"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// SetNamingStrategy rename struct fields uniformly
|
|
func SetNamingStrategy(translate func(string) string) {
|
|
jsoniter.RegisterExtension(&namingStrategyExtension{jsoniter.DummyExtension{}, translate})
|
|
}
|
|
|
|
type namingStrategyExtension struct {
|
|
jsoniter.DummyExtension
|
|
translate func(string) string
|
|
}
|
|
|
|
func (extension *namingStrategyExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor) {
|
|
for _, binding := range structDescriptor.Fields {
|
|
tag, hastag := binding.Field.Tag().Lookup("json")
|
|
if hastag {
|
|
tagParts := strings.Split(tag, ",")
|
|
if tagParts[0] == "-" {
|
|
continue // hidden field
|
|
}
|
|
if tagParts[0] != "" {
|
|
continue // field explicitly named
|
|
}
|
|
}
|
|
binding.ToNames = []string{extension.translate(binding.Field.Name())}
|
|
binding.FromNames = []string{extension.translate(binding.Field.Name())}
|
|
}
|
|
}
|
|
|
|
// LowerCaseWithUnderscores one strategy to SetNamingStrategy for. It will change HelloWorld to hello_world.
|
|
func LowerCaseWithUnderscores(name string) string {
|
|
newName := []rune{}
|
|
for i, c := range name {
|
|
if i == 0 {
|
|
newName = append(newName, unicode.ToLower(c))
|
|
} else {
|
|
if unicode.IsUpper(c) {
|
|
newName = append(newName, '_')
|
|
newName = append(newName, unicode.ToLower(c))
|
|
} else {
|
|
newName = append(newName, c)
|
|
}
|
|
}
|
|
}
|
|
return string(newName)
|
|
}
|