go.uber.org/yarpc@v1.72.1/internal/introspection/router.go (about) 1 // Copyright (c) 2022 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package introspection 22 23 import ( 24 "fmt" 25 26 "go.uber.org/yarpc/api/transport" 27 "go.uber.org/yarpc/pkg/procedure" 28 ) 29 30 const proto = "proto" 31 32 // Procedure represent a registered procedure on a dispatcher. 33 type Procedure struct { 34 Name string `json:"name"` 35 Encoding string `json:"encoding"` 36 Signature string `json:"signature"` 37 RPCType string `json:"rpcType"` 38 } 39 40 // ProcedureName outputs a encoding-native procedure name. 41 func (p Procedure) ProcedureName() string { 42 // see transport/grpc/util.go#toFullMethod 43 if p.Encoding == proto { 44 svc, method := procedure.FromName(p.Name) 45 return fmt.Sprintf("/%s/%s", svc, method) 46 } 47 return p.Name 48 } 49 50 // IntrospectProcedures is a convenience function that translate a slice of 51 // transport.Procedure to a slice of introspection.Procedure. 52 func IntrospectProcedures(routerProcs []transport.Procedure) []Procedure { 53 procedures := make([]Procedure, 0, len(routerProcs)) 54 for _, p := range routerProcs { 55 procedures = append(procedures, Procedure{ 56 Name: p.Name, 57 Encoding: string(p.Encoding), 58 Signature: p.Signature, 59 RPCType: p.HandlerSpec.Type().String(), 60 }) 61 } 62 return procedures 63 }