better logic mgmt in output plugins, go fmt

This commit is contained in:
Yann Hamon 2020-05-31 02:10:19 +02:00
parent 224e9ca17d
commit 8eb297d4c4
11 changed files with 93 additions and 79 deletions

8
pkg/cache/main.go vendored
View file

@ -10,15 +10,15 @@ import (
var mu sync.Mutex
var schemas map[string]*gojsonschema.Schema
func init () {
func init() {
schemas = map[string]*gojsonschema.Schema{}
}
func WithCache(downloadSchema func(string, string, string) (*gojsonschema.Schema, error)) (func (string, string, string) (*gojsonschema.Schema, error)) {
func WithCache(downloadSchema func(string, string, string) (*gojsonschema.Schema, error)) func(string, string, string) (*gojsonschema.Schema, error) {
return func(resourceKind, resourceAPIVersion, k8sVersion string) (*gojsonschema.Schema, error) {
cacheKey := fmt.Sprintf("%s-%s-%s", resourceKind, resourceAPIVersion, k8sVersion)
mu.Lock()
cachedSchema, ok := schemas[cacheKey];
cachedSchema, ok := schemas[cacheKey]
mu.Unlock()
if ok {
return cachedSchema, nil
@ -39,4 +39,4 @@ func WithCache(downloadSchema func(string, string, string) (*gojsonschema.Schema
return schema, err
}
}
}