github.com/cloudwego/kitex@v0.9.0/pkg/rpcinfo/convert.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 rpcinfo 18 19 // Taggable is a type that supports setting tag. 20 type Taggable interface { 21 SetTag(key, value string) error 22 } 23 24 // AsTaggable converts an object into a Taggable. Returns nil if impossible. 25 func AsTaggable(i interface{}) Taggable { 26 if v, ok := i.(Taggable); ok { 27 return v 28 } 29 return nil 30 } 31 32 // AsMutableEndpointInfo converts an EndpointInfo into a MutableEndpointInfo. Returns nil if impossible. 33 func AsMutableEndpointInfo(ei EndpointInfo) MutableEndpointInfo { 34 if v, ok := ei.(MutableEndpointInfo); ok { 35 return v 36 } 37 return nil 38 } 39 40 // AsMutableRPCStats converts an rpcStats into a MutableRPCStats. Returns nil if impossible. 41 func AsMutableRPCStats(r RPCStats) MutableRPCStats { 42 if v, ok := r.(*rpcStats); ok { 43 return v 44 } 45 return nil 46 } 47 48 // AsMutableRPCConfig . 49 func AsMutableRPCConfig(r RPCConfig) MutableRPCConfig { 50 if v, ok := r.(MutableRPCConfig); ok { 51 return v 52 } 53 return nil 54 }