github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/runtime/scheme_builder.go (about) 1 /* 2 Copyright 2015 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 runtime 18 19 // SchemeBuilder collects functions that add things to a scheme. It's to allow 20 // code to compile without explicitly referencing generated types. You should 21 // declare one in each package that will have generated deep copy or conversion 22 // functions. 23 type SchemeBuilder []func(*Scheme) error 24 25 // AddToScheme applies all the stored functions to the scheme. A non-nil error 26 // indicates that one function failed and the attempt was abandoned. 27 func (sb *SchemeBuilder) AddToScheme(s *Scheme) error { 28 for _, f := range *sb { 29 if err := f(s); err != nil { 30 return err 31 } 32 } 33 return nil 34 } 35 36 // Register adds a scheme setup function to the list. 37 func (sb *SchemeBuilder) Register(funcs ...func(*Scheme) error) { 38 for _, f := range funcs { 39 *sb = append(*sb, f) 40 } 41 } 42 43 // NewSchemeBuilder calls Register for you. 44 func NewSchemeBuilder(funcs ...func(*Scheme) error) SchemeBuilder { 45 var sb SchemeBuilder 46 sb.Register(funcs...) 47 return sb 48 }