func (r *Registry) SetEnv(name string, env *Env) error {
	r.rwMux.Lock()
	defer r.rwMux.Unlock()
	priorEnv, found := r.envs[name]
	if found {
		for typeName := range priorEnv.Types {
			delete(r.types, typeName)
		}
	}
	baseExprEnv, found := r.exprEnvs[""]
	if !found {
		return fmt.Errorf("missing default expression environment")
	}
	exprEnv, err := baseExprEnv.Extend(env.ExprEnvOptions()...)
	if err != nil {
		return err
	}
	r.exprEnvs[name] = exprEnv
	r.envs[name] = env
	for typeName, typ := range env.Types {
		r.types[typeName] = typ
	}
	return nil
}
SetEnv registers an environment description by fully qualified name.
package model
import (
	"fmt"
	"k8s.io/kube-openapi/pkg/validation/spec"
	"sync"
	"github.com/google/cel-go/cel"
)
type Resolver interface {
	FindEnv(name string) (*Env, bool)
	FindExprEnv(name string) (*cel.Env, bool)
	FindSchema(name string) (*spec.Schema, bool)
	FindType(name string) (*DeclType, bool)
}
func NewRegistry(stdExprEnv *cel.Env) *Registry {
	return &Registry{
		envs:     map[string]*Env{},
		exprEnvs: map[string]*cel.Env{"": stdExprEnv},
		schemas: map[string]*spec.Schema{
			"#anySchema":      AnySchema,
			"#envSchema":      envSchema,
			"#instanceSchema": instanceSchema,
			"#openAPISchema":  schemaDef,
			"#templateSchema": templateSchema,
		},
		types: map[string]*DeclType{
			AnyType.TypeName():       AnyType,
			BoolType.TypeName():      BoolType,
			BytesType.TypeName():     BytesType,
			DoubleType.TypeName():    DoubleType,
			DurationType.TypeName():  DurationType,
			IntType.TypeName():       IntType,
			NullType.TypeName():      NullType,
			PlainTextType.TypeName(): PlainTextType,
			StringType.TypeName():    StringType,
			TimestampType.TypeName(): TimestampType,
			UintType.TypeName():      UintType,
			ListType.TypeName():      ListType,
			MapType.TypeName():       MapType,
		},
	}
}
type Registry struct {
	rwMux     sync.RWMutex
	envs      map[string]*Env
	exprEnvs  map[string]*cel.Env
	schemas   map[string]*spec.Schema
	types     map[string]*DeclType
}
func (r *Registry) FindEnv(name string) (*Env, bool) {
	r.rwMux.RLock()
	defer r.rwMux.RUnlock()
	env, found := r.envs[name]
	return env, found
}
func (r *Registry) FindExprEnv(name string) (*cel.Env, bool) {
	r.rwMux.RLock()
	defer r.rwMux.RUnlock()
	exprEnv, found := r.exprEnvs[name]
	return exprEnv, found
}
func (r *Registry) FindSchema(name string) (*spec.Schema, bool) {
	r.rwMux.RLock()
	defer r.rwMux.RUnlock()
	schema, found := r.schemas[name]
	return schema, found
}
func (r *Registry) FindType(name string) (*DeclType, bool) {
	r.rwMux.RLock()
	defer r.rwMux.RUnlock()
	typ, found := r.types[name]
	if found {
		return typ, true
	}
	return typ, found
}