...

Source file src/k8s.io/client-go/openapi/cached/groupversion.go

Documentation: k8s.io/client-go/openapi/cached

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package cached
    18  
    19  import (
    20  	"sync"
    21  
    22  	"k8s.io/client-go/openapi"
    23  )
    24  
    25  type groupversion struct {
    26  	delegate openapi.GroupVersion
    27  
    28  	lock sync.Mutex
    29  	docs map[string]docInfo
    30  }
    31  
    32  type docInfo struct {
    33  	data []byte
    34  	err  error
    35  }
    36  
    37  func newGroupVersion(delegate openapi.GroupVersion) *groupversion {
    38  	return &groupversion{
    39  		delegate: delegate,
    40  	}
    41  }
    42  
    43  func (g *groupversion) Schema(contentType string) ([]byte, error) {
    44  	g.lock.Lock()
    45  	defer g.lock.Unlock()
    46  
    47  	cachedInfo, ok := g.docs[contentType]
    48  	if !ok {
    49  		if g.docs == nil {
    50  			g.docs = make(map[string]docInfo)
    51  		}
    52  
    53  		cachedInfo.data, cachedInfo.err = g.delegate.Schema(contentType)
    54  		g.docs[contentType] = cachedInfo
    55  	}
    56  
    57  	return cachedInfo.data, cachedInfo.err
    58  }
    59  

View as plain text