1/* 2 * Copyright 2019 gRPC 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 balancerload defines APIs to parse server loads in trailers. The 18// parsed loads are sent to balancers in DoneInfo. 19package balancerload 20 21import ( 22 "google.golang.org/grpc/metadata" 23) 24 25// Parser converts loads from metadata into a concrete type. 26type Parser interface { 27 // Parse parses loads from metadata. 28 Parse(md metadata.MD) interface{} 29} 30 31var parser Parser 32 33// SetParser sets the load parser. 34// 35// Not mutex-protected, should be called before any gRPC functions. 36func SetParser(lr Parser) { 37 parser = lr 38} 39 40// Parse calls parser.Read(). 41func Parse(md metadata.MD) interface{} { 42 if parser == nil { 43 return nil 44 } 45 return parser.Parse(md) 46} 47