github.com/cloudwego/kitex@v0.9.0/internal/client/lock.go (about) 1 /* 2 * Copyright 2021 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 client 18 19 import ( 20 "github.com/cloudwego/kitex/pkg/rpcinfo" 21 "github.com/cloudwego/kitex/pkg/rpcinfo/remoteinfo" 22 ) 23 24 // ConfigLocks records changing made by options that are not allowed further modifications. 25 type ConfigLocks struct { 26 Bits int 27 Tags map[string]struct{} 28 } 29 30 // NewConfigLocks creates a ConfigLocks. 31 func NewConfigLocks() *ConfigLocks { 32 return &ConfigLocks{ 33 Tags: make(map[string]struct{}), 34 } 35 } 36 37 // ApplyLocks applies the locking operations on rpcinfo.RPCConfig and internal.RemoteInfo. 38 func (cl *ConfigLocks) ApplyLocks(cfg rpcinfo.MutableRPCConfig, svr remoteinfo.RemoteInfo) { 39 if cfg != nil { 40 cfg.LockConfig(cl.Bits) 41 } 42 if svr != nil { 43 for t := range cl.Tags { 44 svr.SetTagLock(t) 45 } 46 } 47 } 48 49 // Merge merges another ConfigLocks into the current one. 50 func (cl *ConfigLocks) Merge(c2 *ConfigLocks) { 51 cl.Bits |= c2.Bits 52 for t := range c2.Tags { 53 cl.Tags[t] = struct{}{} 54 } 55 } 56 57 // Zero ConfigLocks clear 58 func (cl *ConfigLocks) Zero() { 59 cl.Bits = 0 60 for k := range cl.Tags { 61 delete(cl.Tags, k) 62 } 63 }