istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/echo/config/param/params.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package param 16 17 // Params for a Template. 18 type Params map[string]any 19 20 // NewParams returns a new Params instance. 21 func NewParams() Params { 22 return make(Params) 23 } 24 25 func (p Params) Get(k string) any { 26 return p[k] 27 } 28 29 func (p Params) GetWellKnown(k WellKnown) any { 30 return p[k.String()] 31 } 32 33 func (p Params) Set(k string, v any) Params { 34 p[k] = v 35 return p 36 } 37 38 func (p Params) SetAll(other Params) Params { 39 for k, v := range other { 40 p[k] = v 41 } 42 return p 43 } 44 45 func (p Params) SetAllNoOverwrite(other Params) Params { 46 for k, v := range other { 47 if !p.Contains(k) { 48 p[k] = v 49 } 50 } 51 return p 52 } 53 54 func (p Params) SetWellKnown(k WellKnown, v any) Params { 55 p[k.String()] = v 56 return p 57 } 58 59 func (p Params) Contains(k string) bool { 60 _, found := p[k] 61 return found 62 } 63 64 func (p Params) ContainsWellKnown(k WellKnown) bool { 65 return p.Contains(k.String()) 66 } 67 68 func (p Params) Copy() Params { 69 if p == nil { 70 return NewParams() 71 } 72 73 out := make(map[string]any) 74 for k, v := range p { 75 out[k] = v 76 } 77 return out 78 }