mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-03 16:16:06 +00:00
refactor to use Schema(contentType)
Kubernetes-commit: e6e6dd826d76a2b19515cd907062f1f74f9e52c2
This commit is contained in:
committed by
Kubernetes Publisher
parent
8b6ceae557
commit
12cafe2b1b
@@ -25,13 +25,13 @@ import (
|
||||
type groupversion struct {
|
||||
delegate openapi.GroupVersion
|
||||
|
||||
jsonOnce sync.Once
|
||||
jsonBytes []byte
|
||||
jsonErr error
|
||||
lock sync.Mutex
|
||||
docs map[string]docInfo
|
||||
}
|
||||
|
||||
pbOnce sync.Once
|
||||
pbBytes []byte
|
||||
pbErr error
|
||||
type docInfo struct {
|
||||
data []byte
|
||||
err error
|
||||
}
|
||||
|
||||
func newGroupVersion(delegate openapi.GroupVersion) *groupversion {
|
||||
@@ -40,18 +40,19 @@ func newGroupVersion(delegate openapi.GroupVersion) *groupversion {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *groupversion) SchemaPB() ([]byte, error) {
|
||||
g.pbOnce.Do(func() {
|
||||
g.pbBytes, g.pbErr = g.delegate.SchemaPB()
|
||||
})
|
||||
func (g *groupversion) Schema(contentType string) ([]byte, error) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
return g.pbBytes, g.pbErr
|
||||
}
|
||||
|
||||
func (g *groupversion) SchemaJSON() ([]byte, error) {
|
||||
g.jsonOnce.Do(func() {
|
||||
g.jsonBytes, g.jsonErr = g.delegate.SchemaJSON()
|
||||
})
|
||||
|
||||
return g.jsonBytes, g.jsonErr
|
||||
cachedInfo, ok := g.docs[contentType]
|
||||
if !ok {
|
||||
if g.docs == nil {
|
||||
g.docs = make(map[string]docInfo)
|
||||
}
|
||||
|
||||
cachedInfo.data, cachedInfo.err = g.delegate.Schema(contentType)
|
||||
g.docs[contentType] = cachedInfo
|
||||
}
|
||||
|
||||
return cachedInfo.data, cachedInfo.err
|
||||
}
|
||||
|
Reference in New Issue
Block a user