mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

* clientv3: fix grpc-go(v1.27.0) incompatible changes to balancer/resolver. * vendor: upgrade gRPC Go to v1.24.0 Picking up some performance improvements and bug fixes. https://github.com/grpc/grpc-go/releases/tag/v1.24.0 Signed-off-by: Gyuho Lee <leegyuho@amazon.com> * vendor: update gRPC Go to v1.26.0 (#11522) * GO111MODULE=on go mod vendor * GO111MODULE=on go mod vendor go 1.14 Bump travis 2 Co-authored-by: EDDYCJY <313687982@qq.com> Co-authored-by: Gyuho Lee <leegyuho@amazon.com> Co-authored-by: Yuchen Zhou <yczhou@google.com>
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
/*
|
|
*
|
|
* Copyright 2019 gRPC authors.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
// Package attributes defines a generic key/value store used in various gRPC
|
|
// components.
|
|
//
|
|
// All APIs in this package are EXPERIMENTAL.
|
|
package attributes
|
|
|
|
import "fmt"
|
|
|
|
// Attributes is an immutable struct for storing and retrieving generic
|
|
// key/value pairs. Keys must be hashable, and users should define their own
|
|
// types for keys.
|
|
type Attributes struct {
|
|
m map[interface{}]interface{}
|
|
}
|
|
|
|
// New returns a new Attributes containing all key/value pairs in kvs. If the
|
|
// same key appears multiple times, the last value overwrites all previous
|
|
// values for that key. Panics if len(kvs) is not even.
|
|
func New(kvs ...interface{}) *Attributes {
|
|
if len(kvs)%2 != 0 {
|
|
panic(fmt.Sprintf("attributes.New called with unexpected input: len(kvs) = %v", len(kvs)))
|
|
}
|
|
a := &Attributes{m: make(map[interface{}]interface{}, len(kvs)/2)}
|
|
for i := 0; i < len(kvs)/2; i++ {
|
|
a.m[kvs[i*2]] = kvs[i*2+1]
|
|
}
|
|
return a
|
|
}
|
|
|
|
// WithValues returns a new Attributes containing all key/value pairs in a and
|
|
// kvs. Panics if len(kvs) is not even. If the same key appears multiple
|
|
// times, the last value overwrites all previous values for that key. To
|
|
// remove an existing key, use a nil value.
|
|
func (a *Attributes) WithValues(kvs ...interface{}) *Attributes {
|
|
if len(kvs)%2 != 0 {
|
|
panic(fmt.Sprintf("attributes.New called with unexpected input: len(kvs) = %v", len(kvs)))
|
|
}
|
|
n := &Attributes{m: make(map[interface{}]interface{}, len(a.m)+len(kvs)/2)}
|
|
for k, v := range a.m {
|
|
n.m[k] = v
|
|
}
|
|
for i := 0; i < len(kvs)/2; i++ {
|
|
n.m[kvs[i*2]] = kvs[i*2+1]
|
|
}
|
|
return n
|
|
}
|
|
|
|
// Value returns the value associated with these attributes for key, or nil if
|
|
// no value is associated with key.
|
|
func (a *Attributes) Value(key interface{}) interface{} {
|
|
return a.m[key]
|
|
}
|