mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
35 lines
688 B
Go
35 lines
688 B
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/xeipuuv/gojsonschema"
|
|
"sync"
|
|
)
|
|
|
|
type SchemaCache struct {
|
|
sync.RWMutex
|
|
schemas map[string]*gojsonschema.Schema
|
|
}
|
|
|
|
func New() *SchemaCache {
|
|
return &SchemaCache{
|
|
schemas: map[string]*gojsonschema.Schema{},
|
|
}
|
|
}
|
|
|
|
func Key(resourceKind, resourceAPIVersion, k8sVersion string) string {
|
|
return fmt.Sprintf("%s-%s-%s", resourceKind, resourceAPIVersion, k8sVersion)
|
|
}
|
|
|
|
func (c *SchemaCache) Get(key string) (*gojsonschema.Schema, bool) {
|
|
c.RLock()
|
|
defer c.RUnlock()
|
|
schema, ok := c.schemas[key]
|
|
return schema, ok
|
|
}
|
|
|
|
func (c *SchemaCache) Set(key string, schema *gojsonschema.Schema) {
|
|
c.Lock()
|
|
defer c.Unlock()
|
|
c.schemas[key] = schema
|
|
}
|