...

Source file src/k8s.io/client-go/openapi/cached/client.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 client struct {
    26  	delegate openapi.Client
    27  
    28  	once   sync.Once
    29  	result map[string]openapi.GroupVersion
    30  	err    error
    31  }
    32  
    33  func NewClient(other openapi.Client) openapi.Client {
    34  	return &client{
    35  		delegate: other,
    36  	}
    37  }
    38  
    39  func (c *client) Paths() (map[string]openapi.GroupVersion, error) {
    40  	c.once.Do(func() {
    41  		uncached, err := c.delegate.Paths()
    42  		if err != nil {
    43  			c.err = err
    44  			return
    45  		}
    46  
    47  		result := make(map[string]openapi.GroupVersion, len(uncached))
    48  		for k, v := range uncached {
    49  			result[k] = newGroupVersion(v)
    50  		}
    51  		c.result = result
    52  	})
    53  	return c.result, c.err
    54  }
    55  

View as plain text