github.com/cloudwego/kitex@v0.9.0/pkg/circuitbreak/item_circuit_breaker.go (about) 1 /* 2 * Copyright 2023 CloudWeGo 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 circuitbreak 18 19 import ( 20 "github.com/cloudwego/configmanager/iface" 21 "github.com/cloudwego/configmanager/util" 22 ) 23 24 var _ iface.ConfigValueItem = (*CBConfigItem)(nil) 25 26 // TypeCircuitBreaker is used as itemKey in ConfigValueImpl 27 const TypeCircuitBreaker iface.ItemType = "cb_config" 28 29 // CBConfigItem is an alias of CBConfig to meet the requirement of iface.ConfigValueItem 30 type CBConfigItem CBConfig 31 32 // CopyDefaultCBConfig returns a copy of default CBConfig, thus avoiding default values changed by business 33 func CopyDefaultCBConfig() iface.ConfigValueItem { 34 c := CBConfigItem(GetDefaultCBConfig()) 35 return c.DeepCopy() 36 } 37 38 // NewCBConfig decodes json bytes to a new CBConfigItem 39 var NewCBConfig = util.JsonInitializer(func() iface.ConfigValueItem { 40 return &CBConfigItem{} 41 }) 42 43 // DeepCopy returns a copy of CBConfigItem 44 func (c *CBConfigItem) DeepCopy() iface.ConfigValueItem { 45 cb := ((*CBConfig)(c)).DeepCopy() 46 return (*CBConfigItem)(cb) 47 } 48 49 // EqualsTo compares two CBConfigItem 50 func (c *CBConfigItem) EqualsTo(other iface.ConfigValueItem) bool { 51 x := (*CBConfig)(c) 52 y := (*CBConfig)(other.(*CBConfigItem)) 53 return x.Equals(y) 54 }