├── cmd ├── pbctl │ ├── .gitignore │ └── pbctl └── pbsrv │ └── main.go ├── vendor ├── google.golang.org │ └── grpc │ │ ├── AUTHORS │ │ ├── install-protobuf.sh │ │ ├── codes │ │ └── code_string.go │ │ ├── codegen.sh │ │ ├── doc.go │ │ ├── naming │ │ ├── go18.go │ │ ├── go17.go │ │ └── naming.go │ │ ├── Makefile │ │ ├── credentials │ │ ├── credentials_util_go18.go │ │ ├── credentials_util_pre_go17.go │ │ └── credentials_util_go17.go │ │ ├── coverage.sh │ │ ├── internal │ │ └── internal.go │ │ ├── transport │ │ ├── log.go │ │ ├── go16.go │ │ ├── go17.go │ │ └── bdp_estimator.go │ │ ├── peer │ │ └── peer.go │ │ ├── README.md │ │ ├── tap │ │ └── tap.go │ │ ├── CONTRIBUTING.md │ │ ├── connectivity │ │ └── connectivity.go │ │ ├── grpclog │ │ ├── logger.go │ │ └── grpclog.go │ │ ├── stats │ │ └── handlers.go │ │ ├── go16.go │ │ ├── backoff.go │ │ ├── trace.go │ │ ├── go17.go │ │ ├── codec.go │ │ ├── keepalive │ │ └── keepalive.go │ │ ├── interceptor.go │ │ ├── proxy.go │ │ └── metadata │ │ └── metadata.go ├── golang.org │ └── x │ │ ├── net │ │ ├── http2 │ │ │ ├── Makefile │ │ │ ├── not_go19.go │ │ │ ├── go16.go │ │ │ ├── go19.go │ │ │ ├── not_go16.go │ │ │ ├── README │ │ │ ├── not_go18.go │ │ │ ├── flow.go │ │ │ ├── go17_not18.go │ │ │ ├── go18.go │ │ │ ├── Dockerfile │ │ │ ├── headermap.go │ │ │ ├── writesched_random.go │ │ │ ├── configure_transport.go │ │ │ ├── not_go17.go │ │ │ ├── go17.go │ │ │ ├── gotrack.go │ │ │ ├── pipe.go │ │ │ ├── databuffer.go │ │ │ └── errors.go │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── context │ │ │ ├── go19.go │ │ │ ├── context.go │ │ │ ├── go17.go │ │ │ └── pre_go19.go │ │ ├── PATENTS │ │ ├── LICENSE │ │ └── idna │ │ │ ├── idna.go │ │ │ └── punycode.go │ │ └── text │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── PATENTS │ │ ├── unicode │ │ ├── norm │ │ │ ├── trie.go │ │ │ ├── input.go │ │ │ ├── transform.go │ │ │ └── readwriter.go │ │ └── bidi │ │ │ └── trieval.go │ │ └── LICENSE └── github.com │ └── golang │ └── protobuf │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── ptypes │ ├── doc.go │ ├── regen.sh │ ├── duration.go │ ├── duration │ │ ├── duration.proto │ │ └── duration.pb.go │ ├── timestamp │ │ └── timestamp.proto │ ├── timestamp.go │ └── any.go │ ├── proto │ ├── Makefile │ ├── testdata │ │ └── Makefile │ └── proto3_proto │ │ └── proto3.proto │ └── protoc-gen-go │ └── descriptor │ └── Makefile ├── api ├── gen.go ├── errors.go └── api.proto ├── contact.proto ├── package.json ├── README.md ├── server └── server.go └── contact.pb.go /cmd/pbctl/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/AUTHORS: -------------------------------------------------------------------------------- 1 | Google Inc. 2 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Makefile: -------------------------------------------------------------------------------- 1 | curlimage: 2 | docker build -t gohttp2/curl . 3 | 4 | -------------------------------------------------------------------------------- /api/gen.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | //go:generate protoc -I=. --proto_path=${GOPATH}/src:. --go_out=plugins=grpc:. --js_out=import_style=commonjs,binary:. api.proto 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /api/errors.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "google.golang.org/grpc/codes" 5 | "google.golang.org/grpc/status" 6 | ) 7 | 8 | var ( 9 | ErrorNotFound = status.Errorf(codes.NotFound, "Contact not found") 10 | ErrorDuplicateContact = status.Errorf(codes.AlreadyExists, "Contact already exists") 11 | ) 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | // not supported prior to go1.9 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 15 | return t1.ExpectContinueTimeout 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | s.RegisterOnShutdown(conf.state.startGracefulShutdown) 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /contact.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package contact; 4 | 5 | message Contact { 6 | string name = 1; 7 | string email = 2; 8 | 9 | repeated PhoneNumber phone_numbers = 3; 10 | PhoneNumber home = 4; 11 | PhoneNumber mobile = 5; 12 | PhoneNumber work = 6; 13 | } 14 | 15 | message PhoneNumber { 16 | enum PhoneType { 17 | MOBILE = 0; 18 | HOME = 1; 19 | WORK = 2; 20 | } 21 | 22 | string number = 1; 23 | PhoneType type = 2; 24 | } 25 | -------------------------------------------------------------------------------- /cmd/pbsrv/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | "github.com/iheanyi/grpc-phonebook/api" 8 | "github.com/iheanyi/grpc-phonebook/server" 9 | 10 | "google.golang.org/grpc" 11 | ) 12 | 13 | func main() { 14 | lis, err := net.Listen("tcp", ":50051") 15 | if err != nil { 16 | log.Fatalf("failed to listen: %v", err) 17 | } 18 | 19 | srv := grpc.NewServer() 20 | 21 | svc := server.New() 22 | api.RegisterPhoneBookServer(srv, svc) 23 | log.Print("Starting up the server") 24 | srv.Serve(lis) 25 | } 26 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/install-protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | die() { 6 | echo "$@" >&2 7 | exit 1 8 | } 9 | 10 | case "$PROTOBUF_VERSION" in 11 | 3*) 12 | basename=protoc-$PROTOBUF_VERSION 13 | ;; 14 | *) 15 | die "unknown protobuf version: $PROTOBUF_VERSION" 16 | ;; 17 | esac 18 | 19 | cd /home/travis 20 | 21 | wget https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename-linux-x86_64.zip 22 | unzip $basename-linux-x86_64.zip 23 | bin/protoc --version 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func configureTransport(t1 *http.Transport) (*Transport, error) { 15 | return nil, errTransportVersion 16 | } 17 | 18 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 19 | return 0 20 | 21 | } 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phonebookctl", 3 | "version": "1.0.0", 4 | "description": "Just an example CLI for a phonebook gRPC client", 5 | "main": "cmd/phonebookctl/main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Iheanyi Ekechukwu", 10 | "license": "MIT", 11 | "dependencies": { 12 | "commander": "^2.11.0", 13 | "console.table": "^0.9.1", 14 | "google-protobuf": "^3.3.0", 15 | "grpc": "^1.4.1", 16 | "inquirer": "^3.1.1", 17 | "install": "^0.10.1", 18 | "npm": "^5.0.4" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codes/code_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Code"; DO NOT EDIT. 2 | 3 | package codes 4 | 5 | import "fmt" 6 | 7 | const _Code_name = "OKCanceledUnknownInvalidArgumentDeadlineExceededNotFoundAlreadyExistsPermissionDeniedResourceExhaustedFailedPreconditionAbortedOutOfRangeUnimplementedInternalUnavailableDataLossUnauthenticated" 8 | 9 | var _Code_index = [...]uint8{0, 2, 10, 17, 32, 48, 56, 69, 85, 102, 120, 127, 137, 150, 158, 169, 177, 192} 10 | 11 | func (i Code) String() string { 12 | if i >= Code(len(_Code_index)-1) { 13 | return fmt.Sprintf("Code(%d)", i) 14 | } 15 | return _Code_name[_Code_index[i]:_Code_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/README: -------------------------------------------------------------------------------- 1 | This is a work-in-progress HTTP/2 implementation for Go. 2 | 3 | It will eventually live in the Go standard library and won't require 4 | any changes to your code to use. It will just be automatic. 5 | 6 | Status: 7 | 8 | * The server support is pretty good. A few things are missing 9 | but are being worked on. 10 | * The client work has just started but shares a lot of code 11 | is coming along much quicker. 12 | 13 | Docs are at https://godoc.org/golang.org/x/net/http2 14 | 15 | Demo test server at https://http2.golang.org/ 16 | 17 | Help & bug reports welcome! 18 | 19 | Contributing: https://golang.org/doc/contribute.html 20 | Bugs: https://golang.org/issue/new?title=x/net/http2:+ 21 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script serves as an example to demonstrate how to generate the gRPC-Go 4 | # interface and the related messages from .proto file. 5 | # 6 | # It assumes the installation of i) Google proto buffer compiler at 7 | # https://github.com/google/protobuf (after v2.6.1) and ii) the Go codegen 8 | # plugin at https://github.com/golang/protobuf (after 2015-02-20). If you have 9 | # not, please install them first. 10 | # 11 | # We recommend running this script at $GOPATH/src. 12 | # 13 | # If this is not what you need, feel free to make your own scripts. Again, this 14 | # script is for demonstration purpose. 15 | # 16 | proto=$1 17 | protoc --go_out=plugins=grpc:. $proto 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package context 8 | 9 | import "context" // standard library's context, as of Go 1.7 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context = context.Context 16 | 17 | // A CancelFunc tells an operation to abandon its work. 18 | // A CancelFunc does not wait for the work to stop. 19 | // After the first call, subsequent calls to a CancelFunc do nothing. 20 | type CancelFunc = context.CancelFunc 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "io" 11 | "net/http" 12 | ) 13 | 14 | func configureServer18(h1 *http.Server, h2 *Server) error { 15 | // No IdleTimeout to sync prior to Go 1.8. 16 | return nil 17 | } 18 | 19 | func shouldLogPanic(panicValue interface{}) bool { 20 | return panicValue != nil 21 | } 22 | 23 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 24 | return nil 25 | } 26 | 27 | func reqBodyIsNoBody(io.ReadCloser) bool { return false } 28 | 29 | func go18httpNoBody() io.ReadCloser { return nil } // for tests only 30 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | /* 20 | Package grpc implements an RPC system called gRPC. 21 | 22 | See grpc.io for more information about gRPC. 23 | */ 24 | package grpc // import "google.golang.org/grpc" 25 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package naming 22 | 23 | import "net" 24 | 25 | var ( 26 | lookupHost = net.DefaultResolver.LookupHost 27 | lookupSRV = net.DefaultResolver.LookupSRV 28 | ) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GRPC Phonebook 2 | 3 | # Setup 4 | 5 | ### Go 6 | 7 | This requires [govendor](https://github.com/kardianos/govendor) to work properly. You can also install the server by doing `go install github.com/iheanyi/grpc-phonebook/cmd/pbsrv` and then running `pbsrv`. 8 | 9 | ### Node.js 10 | 11 | Install dependencies using `npm` or `yarn`. You can run the command line client by doing `./cmd/pbctl/pbctl [options] `. 12 | 13 | ``` 14 | Usage: pbctl [options] [command] 15 | 16 | 17 | Options: 18 | 19 | -V, --version output the version number 20 | -h, --help output usage information 21 | 22 | 23 | Commands: 24 | 25 | create [options] 26 | list 27 | show 28 | delete 29 | 30 | ``` 31 | 32 | Valid options are: 33 | 34 | ``` 35 | -e, --email email for the contact 36 | -w, --work work number for the contact 37 | -h, --home home number for the contact 38 | -m, --mobile mobile number for the contact 39 | ``` 40 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.6, !go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package naming 22 | 23 | import ( 24 | "net" 25 | 26 | "golang.org/x/net/context" 27 | ) 28 | 29 | var ( 30 | lookupHost = func(ctx context.Context, host string) ([]string, error) { return net.LookupHost(host) } 31 | lookupSRV = func(ctx context.Context, service, proto, name string) (string, []*net.SRV, error) { 32 | return net.LookupSRV(service, proto, name) 33 | } 34 | ) 35 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/Makefile: -------------------------------------------------------------------------------- 1 | all: test testrace 2 | 3 | deps: 4 | go get -d -v google.golang.org/grpc/... 5 | 6 | updatedeps: 7 | go get -d -v -u -f google.golang.org/grpc/... 8 | 9 | testdeps: 10 | go get -d -v -t google.golang.org/grpc/... 11 | 12 | updatetestdeps: 13 | go get -d -v -t -u -f google.golang.org/grpc/... 14 | 15 | build: deps 16 | go build google.golang.org/grpc/... 17 | 18 | proto: 19 | @ if ! which protoc > /dev/null; then \ 20 | echo "error: protoc not installed" >&2; \ 21 | exit 1; \ 22 | fi 23 | go get -u -v github.com/golang/protobuf/protoc-gen-go golang.org/x/tools/cmd/stringer 24 | go generate google.golang.org/grpc/... 25 | 26 | test: testdeps 27 | go test -v -cpu 1,4 google.golang.org/grpc/... 28 | 29 | testrace: testdeps 30 | go test -v -race -cpu 1,4 google.golang.org/grpc/... 31 | 32 | clean: 33 | go clean -i google.golang.org/grpc/... 34 | 35 | coverage: testdeps 36 | ./coverage.sh --coveralls 37 | 38 | .PHONY: \ 39 | all \ 40 | deps \ 41 | updatedeps \ 42 | testdeps \ 43 | updatetestdeps \ 44 | build \ 45 | proto \ 46 | test \ 47 | testrace \ 48 | clean \ 49 | coverage 50 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_go18.go: -------------------------------------------------------------------------------- 1 | // +build go1.8 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package credentials 22 | 23 | import ( 24 | "crypto/tls" 25 | ) 26 | 27 | // cloneTLSConfig returns a shallow clone of the exported 28 | // fields of cfg, ignoring the unexported sync.Once, which 29 | // contains a mutex and must not be copied. 30 | // 31 | // If cfg is nil, a new zero tls.Config is returned. 32 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 33 | if cfg == nil { 34 | return &tls.Config{} 35 | } 36 | 37 | return cfg.Clone() 38 | } 39 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/flow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Flow control 6 | 7 | package http2 8 | 9 | // flow is the flow control window's size. 10 | type flow struct { 11 | // n is the number of DATA bytes we're allowed to send. 12 | // A flow is kept both on a conn and a per-stream. 13 | n int32 14 | 15 | // conn points to the shared connection-level flow that is 16 | // shared by all streams on that conn. It is nil for the flow 17 | // that's on the conn directly. 18 | conn *flow 19 | } 20 | 21 | func (f *flow) setConnFlow(cf *flow) { f.conn = cf } 22 | 23 | func (f *flow) available() int32 { 24 | n := f.n 25 | if f.conn != nil && f.conn.n < n { 26 | n = f.conn.n 27 | } 28 | return n 29 | } 30 | 31 | func (f *flow) take(n int32) { 32 | if n > f.available() { 33 | panic("internal error: took too much") 34 | } 35 | f.n -= n 36 | if f.conn != nil { 37 | f.conn.n -= n 38 | } 39 | } 40 | 41 | // add adds n bytes (positive or negative) to the flow control window. 42 | // It returns false if the sum would exceed 2^31-1. 43 | func (f *flow) add(n int32) bool { 44 | remain := (1<<31 - 1) - f.n 45 | if n > remain { 46 | return false 47 | } 48 | f.n += n 49 | return true 50 | } 51 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | set -e 5 | 6 | workdir=.cover 7 | profile="$workdir/cover.out" 8 | mode=set 9 | end2endtest="google.golang.org/grpc/test" 10 | 11 | generate_cover_data() { 12 | rm -rf "$workdir" 13 | mkdir "$workdir" 14 | 15 | for pkg in "$@"; do 16 | if [ $pkg == "google.golang.org/grpc" -o $pkg == "google.golang.org/grpc/transport" -o $pkg == "google.golang.org/grpc/metadata" -o $pkg == "google.golang.org/grpc/credentials" ] 17 | then 18 | f="$workdir/$(echo $pkg | tr / -)" 19 | go test -covermode="$mode" -coverprofile="$f.cover" "$pkg" 20 | go test -covermode="$mode" -coverpkg "$pkg" -coverprofile="$f.e2e.cover" "$end2endtest" 21 | fi 22 | done 23 | 24 | echo "mode: $mode" >"$profile" 25 | grep -h -v "^mode:" "$workdir"/*.cover >>"$profile" 26 | } 27 | 28 | show_cover_report() { 29 | go tool cover -${1}="$profile" 30 | } 31 | 32 | push_to_coveralls() { 33 | goveralls -coverprofile="$profile" 34 | } 35 | 36 | generate_cover_data $(go list ./...) 37 | show_cover_report func 38 | case "$1" in 39 | "") 40 | ;; 41 | --html) 42 | show_cover_report html ;; 43 | --coveralls) 44 | push_to_coveralls ;; 45 | *) 46 | echo >&2 "error: invalid option: $1" ;; 47 | esac 48 | rm -rf "$workdir" 49 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 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 | 18 | // Package internal contains gRPC-internal code for testing, to avoid polluting 19 | // the godoc of the top-level grpc package. 20 | package internal 21 | 22 | // TestingCloseConns closes all existing transports but keeps 23 | // grpcServer.lis accepting new connections. 24 | // 25 | // The provided grpcServer must be of type *grpc.Server. It is untyped 26 | // for circular dependency reasons. 27 | var TestingCloseConns func(grpcServer interface{}) 28 | 29 | // TestingUseHandlerImpl enables the http.Handler-based server implementation. 30 | // It must be called before Serve and requires TLS credentials. 31 | // 32 | // The provided grpcServer must be of type *grpc.Server. It is untyped 33 | // for circular dependency reasons. 34 | var TestingUseHandlerImpl func(grpcServer interface{}) 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | type valueRange struct { 8 | value uint16 // header: value:stride 9 | lo, hi byte // header: lo:n 10 | } 11 | 12 | type sparseBlocks struct { 13 | values []valueRange 14 | offset []uint16 15 | } 16 | 17 | var nfcSparse = sparseBlocks{ 18 | values: nfcSparseValues[:], 19 | offset: nfcSparseOffset[:], 20 | } 21 | 22 | var nfkcSparse = sparseBlocks{ 23 | values: nfkcSparseValues[:], 24 | offset: nfkcSparseOffset[:], 25 | } 26 | 27 | var ( 28 | nfcData = newNfcTrie(0) 29 | nfkcData = newNfkcTrie(0) 30 | ) 31 | 32 | // lookupValue determines the type of block n and looks up the value for b. 33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 34 | // is a list of ranges with an accompanying value. Given a matching range r, 35 | // the value for b is by r.value + (b - r.lo) * stride. 36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 37 | offset := t.offset[n] 38 | header := t.values[offset] 39 | lo := offset + 1 40 | hi := lo + uint16(header.lo) 41 | for lo < hi { 42 | m := lo + (hi-lo)/2 43 | r := t.values[m] 44 | if r.lo <= b && b <= r.hi { 45 | return r.value + uint16(b-r.lo)*header.value 46 | } 47 | if b < r.lo { 48 | hi = m 49 | } else { 50 | lo = m + 1 51 | } 52 | } 53 | return 0 54 | } 55 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/log.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This file contains wrappers for grpclog functions. 20 | // The transport package only logs to verbose level 2 by default. 21 | 22 | package transport 23 | 24 | import "google.golang.org/grpc/grpclog" 25 | 26 | const logLevel = 2 27 | 28 | func infof(format string, args ...interface{}) { 29 | if grpclog.V(logLevel) { 30 | grpclog.Infof(format, args...) 31 | } 32 | } 33 | 34 | func warningf(format string, args ...interface{}) { 35 | if grpclog.V(logLevel) { 36 | grpclog.Warningf(format, args...) 37 | } 38 | } 39 | 40 | func errorf(format string, args ...interface{}) { 41 | if grpclog.V(logLevel) { 42 | grpclog.Errorf(format, args...) 43 | } 44 | } 45 | 46 | func fatalf(format string, args ...interface{}) { 47 | if grpclog.V(logLevel) { 48 | grpclog.Fatalf(format, args...) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17_not18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7,!go1.8 6 | 7 | package http2 8 | 9 | import "crypto/tls" 10 | 11 | // temporary copy of Go 1.7's private tls.Config.clone: 12 | func cloneTLSConfig(c *tls.Config) *tls.Config { 13 | return &tls.Config{ 14 | Rand: c.Rand, 15 | Time: c.Time, 16 | Certificates: c.Certificates, 17 | NameToCertificate: c.NameToCertificate, 18 | GetCertificate: c.GetCertificate, 19 | RootCAs: c.RootCAs, 20 | NextProtos: c.NextProtos, 21 | ServerName: c.ServerName, 22 | ClientAuth: c.ClientAuth, 23 | ClientCAs: c.ClientCAs, 24 | InsecureSkipVerify: c.InsecureSkipVerify, 25 | CipherSuites: c.CipherSuites, 26 | PreferServerCipherSuites: c.PreferServerCipherSuites, 27 | SessionTicketsDisabled: c.SessionTicketsDisabled, 28 | SessionTicketKey: c.SessionTicketKey, 29 | ClientSessionCache: c.ClientSessionCache, 30 | MinVersion: c.MinVersion, 31 | MaxVersion: c.MaxVersion, 32 | CurvePreferences: c.CurvePreferences, 33 | DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, 34 | Renegotiation: c.Renegotiation, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/go16.go: -------------------------------------------------------------------------------- 1 | // +build go1.6,!go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package transport 22 | 23 | import ( 24 | "net" 25 | 26 | "google.golang.org/grpc/codes" 27 | 28 | "golang.org/x/net/context" 29 | ) 30 | 31 | // dialContext connects to the address on the named network. 32 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 33 | return (&net.Dialer{Cancel: ctx.Done()}).Dial(network, address) 34 | } 35 | 36 | // ContextErr converts the error from context package into a StreamError. 37 | func ContextErr(err error) StreamError { 38 | switch err { 39 | case context.DeadlineExceeded: 40 | return streamErrorf(codes.DeadlineExceeded, "%v", err) 41 | case context.Canceled: 42 | return streamErrorf(codes.Canceled, "%v", err) 43 | } 44 | return streamErrorf(codes.Internal, "Unexpected error from context packet: %v", err) 45 | } 46 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "io" 12 | "net/http" 13 | ) 14 | 15 | func cloneTLSConfig(c *tls.Config) *tls.Config { 16 | c2 := c.Clone() 17 | c2.GetClientCertificate = c.GetClientCertificate // golang.org/issue/19264 18 | return c2 19 | } 20 | 21 | var _ http.Pusher = (*responseWriter)(nil) 22 | 23 | // Push implements http.Pusher. 24 | func (w *responseWriter) Push(target string, opts *http.PushOptions) error { 25 | internalOpts := pushOptions{} 26 | if opts != nil { 27 | internalOpts.Method = opts.Method 28 | internalOpts.Header = opts.Header 29 | } 30 | return w.push(target, internalOpts) 31 | } 32 | 33 | func configureServer18(h1 *http.Server, h2 *Server) error { 34 | if h2.IdleTimeout == 0 { 35 | if h1.IdleTimeout != 0 { 36 | h2.IdleTimeout = h1.IdleTimeout 37 | } else { 38 | h2.IdleTimeout = h1.ReadTimeout 39 | } 40 | } 41 | return nil 42 | } 43 | 44 | func shouldLogPanic(panicValue interface{}) bool { 45 | return panicValue != nil && panicValue != http.ErrAbortHandler 46 | } 47 | 48 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 49 | return req.GetBody 50 | } 51 | 52 | func reqBodyIsNoBody(body io.ReadCloser) bool { 53 | return body == http.NoBody 54 | } 55 | 56 | func go18httpNoBody() io.ReadCloser { return http.NoBody } // for tests only 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package transport 22 | 23 | import ( 24 | "context" 25 | "net" 26 | 27 | "google.golang.org/grpc/codes" 28 | 29 | netctx "golang.org/x/net/context" 30 | ) 31 | 32 | // dialContext connects to the address on the named network. 33 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 34 | return (&net.Dialer{}).DialContext(ctx, network, address) 35 | } 36 | 37 | // ContextErr converts the error from context package into a StreamError. 38 | func ContextErr(err error) StreamError { 39 | switch err { 40 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 41 | return streamErrorf(codes.DeadlineExceeded, "%v", err) 42 | case context.Canceled, netctx.Canceled: 43 | return streamErrorf(codes.Canceled, "%v", err) 44 | } 45 | return streamErrorf(codes.Internal, "Unexpected error from context packet: %v", err) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # This Dockerfile builds a recent curl with HTTP/2 client support, using 3 | # a recent nghttp2 build. 4 | # 5 | # See the Makefile for how to tag it. If Docker and that image is found, the 6 | # Go tests use this curl binary for integration tests. 7 | # 8 | 9 | FROM ubuntu:trusty 10 | 11 | RUN apt-get update && \ 12 | apt-get upgrade -y && \ 13 | apt-get install -y git-core build-essential wget 14 | 15 | RUN apt-get install -y --no-install-recommends \ 16 | autotools-dev libtool pkg-config zlib1g-dev \ 17 | libcunit1-dev libssl-dev libxml2-dev libevent-dev \ 18 | automake autoconf 19 | 20 | # The list of packages nghttp2 recommends for h2load: 21 | RUN apt-get install -y --no-install-recommends make binutils \ 22 | autoconf automake autotools-dev \ 23 | libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \ 24 | libev-dev libevent-dev libjansson-dev libjemalloc-dev \ 25 | cython python3.4-dev python-setuptools 26 | 27 | # Note: setting NGHTTP2_VER before the git clone, so an old git clone isn't cached: 28 | ENV NGHTTP2_VER 895da9a 29 | RUN cd /root && git clone https://github.com/tatsuhiro-t/nghttp2.git 30 | 31 | WORKDIR /root/nghttp2 32 | RUN git reset --hard $NGHTTP2_VER 33 | RUN autoreconf -i 34 | RUN automake 35 | RUN autoconf 36 | RUN ./configure 37 | RUN make 38 | RUN make install 39 | 40 | WORKDIR /root 41 | RUN wget http://curl.haxx.se/download/curl-7.45.0.tar.gz 42 | RUN tar -zxvf curl-7.45.0.tar.gz 43 | WORKDIR /root/curl-7.45.0 44 | RUN ./configure --with-ssl --with-nghttp2=/usr/local 45 | RUN make 46 | RUN make install 47 | RUN ldconfig 48 | 49 | CMD ["-h"] 50 | ENTRYPOINT ["/usr/local/bin/curl"] 51 | 52 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/peer/peer.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package peer defines various peer information associated with RPCs and 20 | // corresponding utils. 21 | package peer 22 | 23 | import ( 24 | "net" 25 | 26 | "golang.org/x/net/context" 27 | "google.golang.org/grpc/credentials" 28 | ) 29 | 30 | // Peer contains the information of the peer for an RPC, such as the address 31 | // and authentication information. 32 | type Peer struct { 33 | // Addr is the peer address. 34 | Addr net.Addr 35 | // AuthInfo is the authentication information of the transport. 36 | // It is nil if there is no transport security being used. 37 | AuthInfo credentials.AuthInfo 38 | } 39 | 40 | type peerKey struct{} 41 | 42 | // NewContext creates a new context with peer information attached. 43 | func NewContext(ctx context.Context, p *Peer) context.Context { 44 | return context.WithValue(ctx, peerKey{}, p) 45 | } 46 | 47 | // FromContext returns the peer information in ctx if it exists. 48 | func FromContext(ctx context.Context) (p *Peer, ok bool) { 49 | p, ok = ctx.Value(peerKey{}).(*Peer) 50 | return 51 | } 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/headermap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "net/http" 9 | "strings" 10 | ) 11 | 12 | var ( 13 | commonLowerHeader = map[string]string{} // Go-Canonical-Case -> lower-case 14 | commonCanonHeader = map[string]string{} // lower-case -> Go-Canonical-Case 15 | ) 16 | 17 | func init() { 18 | for _, v := range []string{ 19 | "accept", 20 | "accept-charset", 21 | "accept-encoding", 22 | "accept-language", 23 | "accept-ranges", 24 | "age", 25 | "access-control-allow-origin", 26 | "allow", 27 | "authorization", 28 | "cache-control", 29 | "content-disposition", 30 | "content-encoding", 31 | "content-language", 32 | "content-length", 33 | "content-location", 34 | "content-range", 35 | "content-type", 36 | "cookie", 37 | "date", 38 | "etag", 39 | "expect", 40 | "expires", 41 | "from", 42 | "host", 43 | "if-match", 44 | "if-modified-since", 45 | "if-none-match", 46 | "if-unmodified-since", 47 | "last-modified", 48 | "link", 49 | "location", 50 | "max-forwards", 51 | "proxy-authenticate", 52 | "proxy-authorization", 53 | "range", 54 | "referer", 55 | "refresh", 56 | "retry-after", 57 | "server", 58 | "set-cookie", 59 | "strict-transport-security", 60 | "trailer", 61 | "transfer-encoding", 62 | "user-agent", 63 | "vary", 64 | "via", 65 | "www-authenticate", 66 | } { 67 | chk := http.CanonicalHeaderKey(v) 68 | commonLowerHeader[chk] = v 69 | commonCanonHeader[v] = chk 70 | } 71 | } 72 | 73 | func lowerHeader(v string) string { 74 | if s, ok := commonLowerHeader[v]; ok { 75 | return s 76 | } 77 | return strings.ToLower(v) 78 | } 79 | -------------------------------------------------------------------------------- /api/api.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | service PhoneBook { 6 | rpc CreateContact(CreateContactReq) returns (CreateContactRes); 7 | rpc ListContacts(ListContactsReq) returns (ListContactsRes); 8 | rpc DeleteContact(DeleteContactReq) returns (DeleteContactRes); 9 | rpc ShowContact(ShowContactReq) returns (ShowContactRes); 10 | rpc UpdateContact(UpdateContactReq) returns (UpdateContactRes); 11 | } 12 | 13 | message CreateContactReq { 14 | string name = 1; 15 | string email = 2; 16 | repeated PhoneNumber phone_numbers = 3; 17 | 18 | PhoneNumber home = 4; 19 | PhoneNumber mobile = 5; 20 | PhoneNumber work = 6; 21 | } 22 | 23 | message CreateContactRes { 24 | Contact contact = 1; 25 | } 26 | 27 | message ListContactsReq {} 28 | 29 | message ListContactsRes { 30 | repeated Contact contacts = 1; 31 | } 32 | 33 | message DeleteContactReq { 34 | string name = 1; // Gonna use just the name for now, lol. 35 | } 36 | 37 | message DeleteContactRes { 38 | Contact contact = 1; 39 | } 40 | 41 | message ShowContactReq { 42 | string name = 1; 43 | } 44 | 45 | message ShowContactRes { 46 | Contact contact = 1; 47 | } 48 | 49 | message UpdateContactReq { 50 | string name = 1; 51 | string email = 2; 52 | repeated PhoneNumber phone_numbers = 3; 53 | 54 | PhoneNumber home = 4; 55 | PhoneNumber mobile = 5; 56 | PhoneNumber work = 6; 57 | 58 | } 59 | 60 | message UpdateContactRes{ 61 | Contact contact = 1; 62 | } 63 | 64 | message Contact { 65 | string name = 1; 66 | string email = 2; 67 | 68 | repeated PhoneNumber phone_numbers = 3; 69 | PhoneNumber home = 4; 70 | PhoneNumber mobile = 5; 71 | PhoneNumber work = 6; 72 | } 73 | 74 | message PhoneNumber { 75 | enum PhoneType { 76 | MOBILE = 0; 77 | HOME = 1; 78 | WORK = 2; 79 | } 80 | 81 | string number = 1; 82 | PhoneType type = 2; 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/doc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | /* 33 | Package ptypes contains code for interacting with well-known types. 34 | */ 35 | package ptypes 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package bidi 4 | 5 | // Class is the Unicode BiDi class. Each rune has a single class. 6 | type Class uint 7 | 8 | const ( 9 | L Class = iota // LeftToRight 10 | R // RightToLeft 11 | EN // EuropeanNumber 12 | ES // EuropeanSeparator 13 | ET // EuropeanTerminator 14 | AN // ArabicNumber 15 | CS // CommonSeparator 16 | B // ParagraphSeparator 17 | S // SegmentSeparator 18 | WS // WhiteSpace 19 | ON // OtherNeutral 20 | BN // BoundaryNeutral 21 | NSM // NonspacingMark 22 | AL // ArabicLetter 23 | Control // Control LRO - PDI 24 | 25 | numClass 26 | 27 | LRO // LeftToRightOverride 28 | RLO // RightToLeftOverride 29 | LRE // LeftToRightEmbedding 30 | RLE // RightToLeftEmbedding 31 | PDF // PopDirectionalFormat 32 | LRI // LeftToRightIsolate 33 | RLI // RightToLeftIsolate 34 | FSI // FirstStrongIsolate 35 | PDI // PopDirectionalIsolate 36 | 37 | unknownClass = ^Class(0) 38 | ) 39 | 40 | var controlToClass = map[rune]Class{ 41 | 0x202D: LRO, // LeftToRightOverride, 42 | 0x202E: RLO, // RightToLeftOverride, 43 | 0x202A: LRE, // LeftToRightEmbedding, 44 | 0x202B: RLE, // RightToLeftEmbedding, 45 | 0x202C: PDF, // PopDirectionalFormat, 46 | 0x2066: LRI, // LeftToRightIsolate, 47 | 0x2067: RLI, // RightToLeftIsolate, 48 | 0x2068: FSI, // FirstStrongIsolate, 49 | 0x2069: PDI, // PopDirectionalIsolate, 50 | } 51 | 52 | // A trie entry has the following bits: 53 | // 7..5 XOR mask for brackets 54 | // 4 1: Bracket open, 0: Bracket close 55 | // 3..0 Class type 56 | 57 | const ( 58 | openMask = 0x10 59 | xorMaskShift = 5 60 | ) 61 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/README.md: -------------------------------------------------------------------------------- 1 | # gRPC-Go 2 | 3 | [![Build Status](https://travis-ci.org/grpc/grpc-go.svg)](https://travis-ci.org/grpc/grpc-go) [![GoDoc](https://godoc.org/google.golang.org/grpc?status.svg)](https://godoc.org/google.golang.org/grpc) 4 | 5 | The Go implementation of [gRPC](https://grpc.io/): A high performance, open source, general RPC framework that puts mobile and HTTP/2 first. For more information see the [gRPC Quick Start: Go](https://grpc.io/docs/quickstart/go.html) guide. 6 | 7 | Installation 8 | ------------ 9 | 10 | To install this package, you need to install Go and setup your Go workspace on your computer. The simplest way to install the library is to run: 11 | 12 | ``` 13 | $ go get -u google.golang.org/grpc 14 | ``` 15 | 16 | Prerequisites 17 | ------------- 18 | 19 | This requires Go 1.6 or later. 20 | 21 | Constraints 22 | ----------- 23 | The grpc package should only depend on standard Go packages and a small number of exceptions. If your contribution introduces new dependencies which are NOT in the [list](http://godoc.org/google.golang.org/grpc?imports), you need a discussion with gRPC-Go authors and consultants. 24 | 25 | Documentation 26 | ------------- 27 | See [API documentation](https://godoc.org/google.golang.org/grpc) for package and API descriptions and find examples in the [examples directory](examples/). 28 | 29 | Performance 30 | ----------- 31 | See the current benchmarks for some of the languages supported in [this dashboard](https://performance-dot-grpc-testing.appspot.com/explore?dashboard=5652536396611584&widget=490377658&container=1286539696). 32 | 33 | Status 34 | ------ 35 | General Availability [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages). 36 | 37 | FAQ 38 | --- 39 | 40 | #### Compiling error, undefined: grpc.SupportPackageIsVersion 41 | 42 | Please update proto package, gRPC package and rebuild the proto files: 43 | - `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}` 44 | - `go get -u google.golang.org/grpc` 45 | - `protoc --go_out=plugins=grpc:. *.proto` 46 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/regen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # This script fetches and rebuilds the "well-known types" protocol buffers. 4 | # To run this you will need protoc and goprotobuf installed; 5 | # see https://github.com/golang/protobuf for instructions. 6 | # You also need Go and Git installed. 7 | 8 | PKG=github.com/golang/protobuf/ptypes 9 | UPSTREAM=https://github.com/google/protobuf 10 | UPSTREAM_SUBDIR=src/google/protobuf 11 | PROTO_FILES=' 12 | any.proto 13 | duration.proto 14 | empty.proto 15 | struct.proto 16 | timestamp.proto 17 | wrappers.proto 18 | ' 19 | 20 | function die() { 21 | echo 1>&2 $* 22 | exit 1 23 | } 24 | 25 | # Sanity check that the right tools are accessible. 26 | for tool in go git protoc protoc-gen-go; do 27 | q=$(which $tool) || die "didn't find $tool" 28 | echo 1>&2 "$tool: $q" 29 | done 30 | 31 | tmpdir=$(mktemp -d -t regen-wkt.XXXXXX) 32 | trap 'rm -rf $tmpdir' EXIT 33 | 34 | echo -n 1>&2 "finding package dir... " 35 | pkgdir=$(go list -f '{{.Dir}}' $PKG) 36 | echo 1>&2 $pkgdir 37 | base=$(echo $pkgdir | sed "s,/$PKG\$,,") 38 | echo 1>&2 "base: $base" 39 | cd $base 40 | 41 | echo 1>&2 "fetching latest protos... " 42 | git clone -q $UPSTREAM $tmpdir 43 | # Pass 1: build mapping from upstream filename to our filename. 44 | declare -A filename_map 45 | for f in $(cd $PKG && find * -name '*.proto'); do 46 | echo -n 1>&2 "looking for latest version of $f... " 47 | up=$(cd $tmpdir/$UPSTREAM_SUBDIR && find * -name $(basename $f) | grep -v /testdata/) 48 | echo 1>&2 $up 49 | if [ $(echo $up | wc -w) != "1" ]; then 50 | die "not exactly one match" 51 | fi 52 | filename_map[$up]=$f 53 | done 54 | # Pass 2: copy files 55 | for up in "${!filename_map[@]}"; do 56 | f=${filename_map[$up]} 57 | shortname=$(basename $f | sed 's,\.proto$,,') 58 | cp $tmpdir/$UPSTREAM_SUBDIR/$up $PKG/$f 59 | done 60 | 61 | # Run protoc once per package. 62 | for dir in $(find $PKG -name '*.proto' | xargs dirname | sort | uniq); do 63 | echo 1>&2 "* $dir" 64 | protoc --go_out=. $dir/*.proto 65 | done 66 | echo 1>&2 "All OK" 67 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/idna.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package idna implements IDNA2008 (Internationalized Domain Names for 6 | // Applications), defined in RFC 5890, RFC 5891, RFC 5892, RFC 5893 and 7 | // RFC 5894. 8 | package idna // import "golang.org/x/net/idna" 9 | 10 | import ( 11 | "strings" 12 | "unicode/utf8" 13 | ) 14 | 15 | // TODO(nigeltao): specify when errors occur. For example, is ToASCII(".") or 16 | // ToASCII("foo\x00") an error? See also http://www.unicode.org/faq/idn.html#11 17 | 18 | // acePrefix is the ASCII Compatible Encoding prefix. 19 | const acePrefix = "xn--" 20 | 21 | // ToASCII converts a domain or domain label to its ASCII form. For example, 22 | // ToASCII("bücher.example.com") is "xn--bcher-kva.example.com", and 23 | // ToASCII("golang") is "golang". 24 | func ToASCII(s string) (string, error) { 25 | if ascii(s) { 26 | return s, nil 27 | } 28 | labels := strings.Split(s, ".") 29 | for i, label := range labels { 30 | if !ascii(label) { 31 | a, err := encode(acePrefix, label) 32 | if err != nil { 33 | return "", err 34 | } 35 | labels[i] = a 36 | } 37 | } 38 | return strings.Join(labels, "."), nil 39 | } 40 | 41 | // ToUnicode converts a domain or domain label to its Unicode form. For example, 42 | // ToUnicode("xn--bcher-kva.example.com") is "bücher.example.com", and 43 | // ToUnicode("golang") is "golang". 44 | func ToUnicode(s string) (string, error) { 45 | if !strings.Contains(s, acePrefix) { 46 | return s, nil 47 | } 48 | labels := strings.Split(s, ".") 49 | for i, label := range labels { 50 | if strings.HasPrefix(label, acePrefix) { 51 | u, err := decode(label[len(acePrefix):]) 52 | if err != nil { 53 | return "", err 54 | } 55 | labels[i] = u 56 | } 57 | } 58 | return strings.Join(labels, "."), nil 59 | } 60 | 61 | func ascii(s string) bool { 62 | for i := 0; i < len(s); i++ { 63 | if s[i] >= utf8.RuneSelf { 64 | return false 65 | } 66 | } 67 | return true 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 33 | include ../../Make.protobuf 34 | 35 | all: regenerate 36 | 37 | regenerate: 38 | rm -f test.pb.go 39 | make test.pb.go 40 | 41 | # The following rules are just aids to development. Not needed for typical testing. 42 | 43 | diff: regenerate 44 | git diff test.pb.go 45 | 46 | restore: 47 | cp test.pb.go.golden test.pb.go 48 | 49 | preserve: 50 | cp test.pb.go test.pb.go.golden 51 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_pre_go17.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package credentials 22 | 23 | import ( 24 | "crypto/tls" 25 | ) 26 | 27 | // cloneTLSConfig returns a shallow clone of the exported 28 | // fields of cfg, ignoring the unexported sync.Once, which 29 | // contains a mutex and must not be copied. 30 | // 31 | // If cfg is nil, a new zero tls.Config is returned. 32 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 33 | if cfg == nil { 34 | return &tls.Config{} 35 | } 36 | return &tls.Config{ 37 | Rand: cfg.Rand, 38 | Time: cfg.Time, 39 | Certificates: cfg.Certificates, 40 | NameToCertificate: cfg.NameToCertificate, 41 | GetCertificate: cfg.GetCertificate, 42 | RootCAs: cfg.RootCAs, 43 | NextProtos: cfg.NextProtos, 44 | ServerName: cfg.ServerName, 45 | ClientAuth: cfg.ClientAuth, 46 | ClientCAs: cfg.ClientCAs, 47 | InsecureSkipVerify: cfg.InsecureSkipVerify, 48 | CipherSuites: cfg.CipherSuites, 49 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 50 | SessionTicketsDisabled: cfg.SessionTicketsDisabled, 51 | SessionTicketKey: cfg.SessionTicketKey, 52 | ClientSessionCache: cfg.ClientSessionCache, 53 | MinVersion: cfg.MinVersion, 54 | MaxVersion: cfg.MaxVersion, 55 | CurvePreferences: cfg.CurvePreferences, 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/writesched_random.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import "math" 8 | 9 | // NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2 10 | // priorities. Control frames like SETTINGS and PING are written before DATA 11 | // frames, but if no control frames are queued and multiple streams have queued 12 | // HEADERS or DATA frames, Pop selects a ready stream arbitrarily. 13 | func NewRandomWriteScheduler() WriteScheduler { 14 | return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)} 15 | } 16 | 17 | type randomWriteScheduler struct { 18 | // zero are frames not associated with a specific stream. 19 | zero writeQueue 20 | 21 | // sq contains the stream-specific queues, keyed by stream ID. 22 | // When a stream is idle or closed, it's deleted from the map. 23 | sq map[uint32]*writeQueue 24 | 25 | // pool of empty queues for reuse. 26 | queuePool writeQueuePool 27 | } 28 | 29 | func (ws *randomWriteScheduler) OpenStream(streamID uint32, options OpenStreamOptions) { 30 | // no-op: idle streams are not tracked 31 | } 32 | 33 | func (ws *randomWriteScheduler) CloseStream(streamID uint32) { 34 | q, ok := ws.sq[streamID] 35 | if !ok { 36 | return 37 | } 38 | delete(ws.sq, streamID) 39 | ws.queuePool.put(q) 40 | } 41 | 42 | func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityParam) { 43 | // no-op: priorities are ignored 44 | } 45 | 46 | func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) { 47 | id := wr.StreamID() 48 | if id == 0 { 49 | ws.zero.push(wr) 50 | return 51 | } 52 | q, ok := ws.sq[id] 53 | if !ok { 54 | q = ws.queuePool.get() 55 | ws.sq[id] = q 56 | } 57 | q.push(wr) 58 | } 59 | 60 | func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) { 61 | // Control frames first. 62 | if !ws.zero.empty() { 63 | return ws.zero.shift(), true 64 | } 65 | // Iterate over all non-idle streams until finding one that can be consumed. 66 | for _, q := range ws.sq { 67 | if wr, ok := q.consume(math.MaxInt32); ok { 68 | return wr, true 69 | } 70 | } 71 | return FrameWriteRequest{}, false 72 | } 73 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/naming/naming.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package naming defines the naming API and related data structures for gRPC. 20 | // The interface is EXPERIMENTAL and may be suject to change. 21 | package naming 22 | 23 | // Operation defines the corresponding operations for a name resolution change. 24 | type Operation uint8 25 | 26 | const ( 27 | // Add indicates a new address is added. 28 | Add Operation = iota 29 | // Delete indicates an exisiting address is deleted. 30 | Delete 31 | ) 32 | 33 | // Update defines a name resolution update. Notice that it is not valid having both 34 | // empty string Addr and nil Metadata in an Update. 35 | type Update struct { 36 | // Op indicates the operation of the update. 37 | Op Operation 38 | // Addr is the updated address. It is empty string if there is no address update. 39 | Addr string 40 | // Metadata is the updated metadata. It is nil if there is no metadata update. 41 | // Metadata is not required for a custom naming implementation. 42 | Metadata interface{} 43 | } 44 | 45 | // Resolver creates a Watcher for a target to track its resolution changes. 46 | type Resolver interface { 47 | // Resolve creates a Watcher for target. 48 | Resolve(target string) (Watcher, error) 49 | } 50 | 51 | // Watcher watches for the updates on the specified target. 52 | type Watcher interface { 53 | // Next blocks until an update or error happens. It may return one or more 54 | // updates. The first call should get the full set of the results. It should 55 | // return an error if and only if Watcher cannot recover. 56 | Next() ([]*Update, error) 57 | // Close closes the Watcher. 58 | Close() 59 | } 60 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/tap/tap.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package tap defines the function handles which are executed on the transport 20 | // layer of gRPC-Go and related information. Everything here is EXPERIMENTAL. 21 | package tap 22 | 23 | import ( 24 | "golang.org/x/net/context" 25 | ) 26 | 27 | // Info defines the relevant information needed by the handles. 28 | type Info struct { 29 | // FullMethodName is the string of grpc method (in the format of 30 | // /package.service/method). 31 | FullMethodName string 32 | // TODO: More to be added. 33 | } 34 | 35 | // ServerInHandle defines the function which runs before a new stream is created 36 | // on the server side. If it returns a non-nil error, the stream will not be 37 | // created and a RST_STREAM will be sent back to the client with REFUSED_STREAM. 38 | // The client will receive an RPC error "code = Unavailable, desc = stream 39 | // terminated by RST_STREAM with error code: REFUSED_STREAM". 40 | // 41 | // It's intended to be used in situations where you don't want to waste the 42 | // resources to accept the new stream (e.g. rate-limiting). And the content of 43 | // the error will be ignored and won't be sent back to the client. For other 44 | // general usages, please use interceptors. 45 | // 46 | // Note that it is executed in the per-connection I/O goroutine(s) instead of 47 | // per-RPC goroutine. Therefore, users should NOT have any 48 | // blocking/time-consuming work in this handle. Otherwise all the RPCs would 49 | // slow down. Also, for the same reason, this handle won't be called 50 | // concurrently by gRPC. 51 | type ServerInHandle func(ctx context.Context, info *Info) (context.Context, error) 52 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Not stored here, but descriptor.proto is in https://github.com/google/protobuf/ 33 | # at src/google/protobuf/descriptor.proto 34 | regenerate: 35 | echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION 36 | protoc --go_out=. -I$(HOME)/src/protobuf/src $(HOME)/src/protobuf/src/google/protobuf/descriptor.proto && \ 37 | sed 's,^package google_protobuf,package descriptor,' google/protobuf/descriptor.pb.go > \ 38 | $(GOPATH)/src/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go && \ 39 | rm -f google/protobuf/descriptor.pb.go 40 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/credentials/credentials_util_go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | // +build !go1.8 3 | 4 | /* 5 | * 6 | * Copyright 2016 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | package credentials 23 | 24 | import ( 25 | "crypto/tls" 26 | ) 27 | 28 | // cloneTLSConfig returns a shallow clone of the exported 29 | // fields of cfg, ignoring the unexported sync.Once, which 30 | // contains a mutex and must not be copied. 31 | // 32 | // If cfg is nil, a new zero tls.Config is returned. 33 | func cloneTLSConfig(cfg *tls.Config) *tls.Config { 34 | if cfg == nil { 35 | return &tls.Config{} 36 | } 37 | return &tls.Config{ 38 | Rand: cfg.Rand, 39 | Time: cfg.Time, 40 | Certificates: cfg.Certificates, 41 | NameToCertificate: cfg.NameToCertificate, 42 | GetCertificate: cfg.GetCertificate, 43 | RootCAs: cfg.RootCAs, 44 | NextProtos: cfg.NextProtos, 45 | ServerName: cfg.ServerName, 46 | ClientAuth: cfg.ClientAuth, 47 | ClientCAs: cfg.ClientCAs, 48 | InsecureSkipVerify: cfg.InsecureSkipVerify, 49 | CipherSuites: cfg.CipherSuites, 50 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 51 | SessionTicketsDisabled: cfg.SessionTicketsDisabled, 52 | SessionTicketKey: cfg.SessionTicketKey, 53 | ClientSessionCache: cfg.ClientSessionCache, 54 | MinVersion: cfg.MinVersion, 55 | MaxVersion: cfg.MaxVersion, 56 | CurvePreferences: cfg.CurvePreferences, 57 | DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled, 58 | Renegotiation: cfg.Renegotiation, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We definitely welcome your patches and contributions to gRPC! 4 | 5 | If you are new to github, please start by reading [Pull Request howto](https://help.github.com/articles/about-pull-requests/) 6 | 7 | ## Legal requirements 8 | 9 | In order to protect both you and ourselves, you will need to sign the 10 | [Contributor License Agreement](https://cla.developers.google.com/clas). 11 | 12 | ## Guidelines for Pull Requests 13 | How to get your contributions merged smoothly and quickly. 14 | 15 | - Create **small PRs** that are narrowly focused on **addressing a single concern**. We often times receive PRs that are trying to fix several things at a time, but only one fix is considered acceptable, nothing gets merged and both author's & review's time is wasted. Create more PRs to address different concerns and everyone will be happy. 16 | 17 | - For speculative changes, consider opening an issue and discussing it first. If you are suggesting a behavioral or API change, consider starting with a [gRFC proposal](https://github.com/grpc/proposal). 18 | 19 | - Provide a good **PR description** as a record of **what** change is being made and **why** it was made. Link to a github issue if it exists. 20 | 21 | - Don't fix code style and formatting unless you are already changing that line to address an issue. PRs with irrelevant changes won't be merged. If you do want to fix formatting or style, do that in a separate PR. 22 | 23 | - Unless your PR is trivial, you should expect there will be reviewer comments that you'll need to address before merging. We expect you to be reasonably responsive to those comments, otherwise the PR will be closed after 2-3 weeks of inactivity. 24 | 25 | - Maintain **clean commit history** and use **meaningful commit messages**. PRs with messy commit history are difficult to review and won't be merged. Use `rebase -i upstream/master` to curate your commit history and/or to bring in latest changes from master (but avoid rebasing in the middle of a code review). 26 | 27 | - Keep your PR up to date with upstream/master (if there are merge conflicts, we can't really merge your change). 28 | 29 | - **All tests need to be passing** before your change can be merged. We recommend you **run tests locally** before creating your PR to catch breakages early on. 30 | 31 | - Exceptions to the rules can be made if there's a compelling reason for doing so. 32 | 33 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/connectivity/connectivity.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package connectivity defines connectivity semantics. 20 | // For details, see https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md. 21 | // All APIs in this package are experimental. 22 | package connectivity 23 | 24 | import ( 25 | "golang.org/x/net/context" 26 | "google.golang.org/grpc/grpclog" 27 | ) 28 | 29 | // State indicates the state of connectivity. 30 | // It can be the state of a ClientConn or SubConn. 31 | type State int 32 | 33 | func (s State) String() string { 34 | switch s { 35 | case Idle: 36 | return "IDLE" 37 | case Connecting: 38 | return "CONNECTING" 39 | case Ready: 40 | return "READY" 41 | case TransientFailure: 42 | return "TRANSIENT_FAILURE" 43 | case Shutdown: 44 | return "SHUTDOWN" 45 | default: 46 | grpclog.Errorf("unknown connectivity state: %d", s) 47 | return "Invalid-State" 48 | } 49 | } 50 | 51 | const ( 52 | // Idle indicates the ClientConn is idle. 53 | Idle State = iota 54 | // Connecting indicates the ClienConn is connecting. 55 | Connecting 56 | // Ready indicates the ClientConn is ready for work. 57 | Ready 58 | // TransientFailure indicates the ClientConn has seen a failure but expects to recover. 59 | TransientFailure 60 | // Shutdown indicates the ClientConn has started shutting down. 61 | Shutdown 62 | ) 63 | 64 | // Reporter reports the connectivity states. 65 | type Reporter interface { 66 | // CurrentState returns the current state of the reporter. 67 | CurrentState() State 68 | // WaitForStateChange blocks until the reporter's state is different from the given state, 69 | // and returns true. 70 | // It returns false if <-ctx.Done() can proceed (ctx got timeout or got canceled). 71 | WaitForStateChange(context.Context, State) bool 72 | } 73 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/grpclog/logger.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpclog 20 | 21 | // Logger mimics golang's standard Logger as an interface. 22 | // Deprecated: use LoggerV2. 23 | type Logger interface { 24 | Fatal(args ...interface{}) 25 | Fatalf(format string, args ...interface{}) 26 | Fatalln(args ...interface{}) 27 | Print(args ...interface{}) 28 | Printf(format string, args ...interface{}) 29 | Println(args ...interface{}) 30 | } 31 | 32 | // SetLogger sets the logger that is used in grpc. Call only from 33 | // init() functions. 34 | // Deprecated: use SetLoggerV2. 35 | func SetLogger(l Logger) { 36 | logger = &loggerWrapper{Logger: l} 37 | } 38 | 39 | // loggerWrapper wraps Logger into a LoggerV2. 40 | type loggerWrapper struct { 41 | Logger 42 | } 43 | 44 | func (g *loggerWrapper) Info(args ...interface{}) { 45 | g.Logger.Print(args...) 46 | } 47 | 48 | func (g *loggerWrapper) Infoln(args ...interface{}) { 49 | g.Logger.Println(args...) 50 | } 51 | 52 | func (g *loggerWrapper) Infof(format string, args ...interface{}) { 53 | g.Logger.Printf(format, args...) 54 | } 55 | 56 | func (g *loggerWrapper) Warning(args ...interface{}) { 57 | g.Logger.Print(args...) 58 | } 59 | 60 | func (g *loggerWrapper) Warningln(args ...interface{}) { 61 | g.Logger.Println(args...) 62 | } 63 | 64 | func (g *loggerWrapper) Warningf(format string, args ...interface{}) { 65 | g.Logger.Printf(format, args...) 66 | } 67 | 68 | func (g *loggerWrapper) Error(args ...interface{}) { 69 | g.Logger.Print(args...) 70 | } 71 | 72 | func (g *loggerWrapper) Errorln(args ...interface{}) { 73 | g.Logger.Println(args...) 74 | } 75 | 76 | func (g *loggerWrapper) Errorf(format string, args ...interface{}) { 77 | g.Logger.Printf(format, args...) 78 | } 79 | 80 | func (g *loggerWrapper) V(l int) bool { 81 | // Returns true for all verbose level. 82 | return true 83 | } 84 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/context.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package context defines the Context type, which carries deadlines, 6 | // cancelation signals, and other request-scoped values across API boundaries 7 | // and between processes. 8 | // 9 | // Incoming requests to a server should create a Context, and outgoing calls to 10 | // servers should accept a Context. The chain of function calls between must 11 | // propagate the Context, optionally replacing it with a modified copy created 12 | // using WithDeadline, WithTimeout, WithCancel, or WithValue. 13 | // 14 | // Programs that use Contexts should follow these rules to keep interfaces 15 | // consistent across packages and enable static analysis tools to check context 16 | // propagation: 17 | // 18 | // Do not store Contexts inside a struct type; instead, pass a Context 19 | // explicitly to each function that needs it. The Context should be the first 20 | // parameter, typically named ctx: 21 | // 22 | // func DoSomething(ctx context.Context, arg Arg) error { 23 | // // ... use ctx ... 24 | // } 25 | // 26 | // Do not pass a nil Context, even if a function permits it. Pass context.TODO 27 | // if you are unsure about which Context to use. 28 | // 29 | // Use context Values only for request-scoped data that transits processes and 30 | // APIs, not for passing optional parameters to functions. 31 | // 32 | // The same Context may be passed to functions running in different goroutines; 33 | // Contexts are safe for simultaneous use by multiple goroutines. 34 | // 35 | // See http://blog.golang.org/context for example code for a server that uses 36 | // Contexts. 37 | package context // import "golang.org/x/net/context" 38 | 39 | // Background returns a non-nil, empty Context. It is never canceled, has no 40 | // values, and has no deadline. It is typically used by the main function, 41 | // initialization, and tests, and as the top-level Context for incoming 42 | // requests. 43 | func Background() Context { 44 | return background 45 | } 46 | 47 | // TODO returns a non-nil, empty Context. Code should use context.TODO when 48 | // it's unclear which Context to use or it is not yet available (because the 49 | // surrounding function has not yet been extended to accept a Context 50 | // parameter). TODO is recognized by static analysis tools that determine 51 | // whether Contexts are propagated correctly in a program. 52 | func TODO() Context { 53 | return todo 54 | } 55 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/stats/handlers.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package stats 20 | 21 | import ( 22 | "net" 23 | 24 | "golang.org/x/net/context" 25 | ) 26 | 27 | // ConnTagInfo defines the relevant information needed by connection context tagger. 28 | type ConnTagInfo struct { 29 | // RemoteAddr is the remote address of the corresponding connection. 30 | RemoteAddr net.Addr 31 | // LocalAddr is the local address of the corresponding connection. 32 | LocalAddr net.Addr 33 | } 34 | 35 | // RPCTagInfo defines the relevant information needed by RPC context tagger. 36 | type RPCTagInfo struct { 37 | // FullMethodName is the RPC method in the format of /package.service/method. 38 | FullMethodName string 39 | // FailFast indicates if this RPC is failfast. 40 | // This field is only valid on client side, it's always false on server side. 41 | FailFast bool 42 | } 43 | 44 | // Handler defines the interface for the related stats handling (e.g., RPCs, connections). 45 | type Handler interface { 46 | // TagRPC can attach some information to the given context. 47 | // The context used for the rest lifetime of the RPC will be derived from 48 | // the returned context. 49 | TagRPC(context.Context, *RPCTagInfo) context.Context 50 | // HandleRPC processes the RPC stats. 51 | HandleRPC(context.Context, RPCStats) 52 | 53 | // TagConn can attach some information to the given context. 54 | // The returned context will be used for stats handling. 55 | // For conn stats handling, the context used in HandleConn for this 56 | // connection will be derived from the context returned. 57 | // For RPC stats handling, 58 | // - On server side, the context used in HandleRPC for all RPCs on this 59 | // connection will be derived from the context returned. 60 | // - On client side, the context is not derived from the context returned. 61 | TagConn(context.Context, *ConnTagInfo) context.Context 62 | // HandleConn processes the Conn stats. 63 | HandleConn(context.Context, ConnStats) 64 | } 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/configure_transport.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "fmt" 12 | "net/http" 13 | ) 14 | 15 | func configureTransport(t1 *http.Transport) (*Transport, error) { 16 | connPool := new(clientConnPool) 17 | t2 := &Transport{ 18 | ConnPool: noDialClientConnPool{connPool}, 19 | t1: t1, 20 | } 21 | connPool.t = t2 22 | if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil { 23 | return nil, err 24 | } 25 | if t1.TLSClientConfig == nil { 26 | t1.TLSClientConfig = new(tls.Config) 27 | } 28 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "h2") { 29 | t1.TLSClientConfig.NextProtos = append([]string{"h2"}, t1.TLSClientConfig.NextProtos...) 30 | } 31 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "http/1.1") { 32 | t1.TLSClientConfig.NextProtos = append(t1.TLSClientConfig.NextProtos, "http/1.1") 33 | } 34 | upgradeFn := func(authority string, c *tls.Conn) http.RoundTripper { 35 | addr := authorityAddr("https", authority) 36 | if used, err := connPool.addConnIfNeeded(addr, t2, c); err != nil { 37 | go c.Close() 38 | return erringRoundTripper{err} 39 | } else if !used { 40 | // Turns out we don't need this c. 41 | // For example, two goroutines made requests to the same host 42 | // at the same time, both kicking off TCP dials. (since protocol 43 | // was unknown) 44 | go c.Close() 45 | } 46 | return t2 47 | } 48 | if m := t1.TLSNextProto; len(m) == 0 { 49 | t1.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{ 50 | "h2": upgradeFn, 51 | } 52 | } else { 53 | m["h2"] = upgradeFn 54 | } 55 | return t2, nil 56 | } 57 | 58 | // registerHTTPSProtocol calls Transport.RegisterProtocol but 59 | // converting panics into errors. 60 | func registerHTTPSProtocol(t *http.Transport, rt http.RoundTripper) (err error) { 61 | defer func() { 62 | if e := recover(); e != nil { 63 | err = fmt.Errorf("%v", e) 64 | } 65 | }() 66 | t.RegisterProtocol("https", rt) 67 | return nil 68 | } 69 | 70 | // noDialH2RoundTripper is a RoundTripper which only tries to complete the request 71 | // if there's already has a cached connection to the host. 72 | type noDialH2RoundTripper struct{ t *Transport } 73 | 74 | func (rt noDialH2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { 75 | res, err := rt.t.RoundTrip(req) 76 | if err == ErrNoCachedConn { 77 | return nil, http.ErrSkipAltProtocol 78 | } 79 | return res, err 80 | } 81 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/input.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "unicode/utf8" 8 | 9 | type input struct { 10 | str string 11 | bytes []byte 12 | } 13 | 14 | func inputBytes(str []byte) input { 15 | return input{bytes: str} 16 | } 17 | 18 | func inputString(str string) input { 19 | return input{str: str} 20 | } 21 | 22 | func (in *input) setBytes(str []byte) { 23 | in.str = "" 24 | in.bytes = str 25 | } 26 | 27 | func (in *input) setString(str string) { 28 | in.str = str 29 | in.bytes = nil 30 | } 31 | 32 | func (in *input) _byte(p int) byte { 33 | if in.bytes == nil { 34 | return in.str[p] 35 | } 36 | return in.bytes[p] 37 | } 38 | 39 | func (in *input) skipASCII(p, max int) int { 40 | if in.bytes == nil { 41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ { 42 | } 43 | } else { 44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ { 45 | } 46 | } 47 | return p 48 | } 49 | 50 | func (in *input) skipContinuationBytes(p int) int { 51 | if in.bytes == nil { 52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ { 53 | } 54 | } else { 55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ { 56 | } 57 | } 58 | return p 59 | } 60 | 61 | func (in *input) appendSlice(buf []byte, b, e int) []byte { 62 | if in.bytes != nil { 63 | return append(buf, in.bytes[b:e]...) 64 | } 65 | for i := b; i < e; i++ { 66 | buf = append(buf, in.str[i]) 67 | } 68 | return buf 69 | } 70 | 71 | func (in *input) copySlice(buf []byte, b, e int) int { 72 | if in.bytes == nil { 73 | return copy(buf, in.str[b:e]) 74 | } 75 | return copy(buf, in.bytes[b:e]) 76 | } 77 | 78 | func (in *input) charinfoNFC(p int) (uint16, int) { 79 | if in.bytes == nil { 80 | return nfcData.lookupString(in.str[p:]) 81 | } 82 | return nfcData.lookup(in.bytes[p:]) 83 | } 84 | 85 | func (in *input) charinfoNFKC(p int) (uint16, int) { 86 | if in.bytes == nil { 87 | return nfkcData.lookupString(in.str[p:]) 88 | } 89 | return nfkcData.lookup(in.bytes[p:]) 90 | } 91 | 92 | func (in *input) hangul(p int) (r rune) { 93 | var size int 94 | if in.bytes == nil { 95 | if !isHangulString(in.str[p:]) { 96 | return 0 97 | } 98 | r, size = utf8.DecodeRuneInString(in.str[p:]) 99 | } else { 100 | if !isHangul(in.bytes[p:]) { 101 | return 0 102 | } 103 | r, size = utf8.DecodeRune(in.bytes[p:]) 104 | } 105 | if size != hangulUTF8Size { 106 | return 0 107 | } 108 | return r 109 | } 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/transform.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import ( 8 | "unicode/utf8" 9 | 10 | "golang.org/x/text/transform" 11 | ) 12 | 13 | // Reset implements the Reset method of the transform.Transformer interface. 14 | func (Form) Reset() {} 15 | 16 | // Transform implements the Transform method of the transform.Transformer 17 | // interface. It may need to write segments of up to MaxSegmentSize at once. 18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at 19 | // least of size MaxTransformChunkSize to be guaranteed of progress. 20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 21 | n := 0 22 | // Cap the maximum number of src bytes to check. 23 | b := src 24 | eof := atEOF 25 | if ns := len(dst); ns < len(b) { 26 | err = transform.ErrShortDst 27 | eof = false 28 | b = b[:ns] 29 | } 30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof) 31 | n += copy(dst[n:], b[n:i]) 32 | if !ok { 33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF) 34 | return nDst + n, nSrc + n, err 35 | } 36 | if n < len(src) && !atEOF { 37 | err = transform.ErrShortSrc 38 | } 39 | return n, n, err 40 | } 41 | 42 | func flushTransform(rb *reorderBuffer) bool { 43 | // Write out (must fully fit in dst, or else it is a ErrShortDst). 44 | if len(rb.out) < rb.nrune*utf8.UTFMax { 45 | return false 46 | } 47 | rb.out = rb.out[rb.flushCopy(rb.out):] 48 | return true 49 | } 50 | 51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc} 52 | 53 | // transform implements the transform.Transformer interface. It is only called 54 | // when quickSpan does not pass for a given string. 55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 56 | // TODO: get rid of reorderBuffer. See CL 23460044. 57 | rb := reorderBuffer{} 58 | rb.init(f, src) 59 | for { 60 | // Load segment into reorder buffer. 61 | rb.setFlusher(dst[nDst:], flushTransform) 62 | end := decomposeSegment(&rb, nSrc, atEOF) 63 | if end < 0 { 64 | return nDst, nSrc, errs[-end] 65 | } 66 | nDst = len(dst) - len(rb.out) 67 | nSrc = end 68 | 69 | // Next quickSpan. 70 | end = rb.nsrc 71 | eof := atEOF 72 | if n := nSrc + len(dst) - nDst; n < end { 73 | err = transform.ErrShortDst 74 | end = n 75 | eof = false 76 | } 77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof) 78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end]) 79 | nSrc += n 80 | nDst += n 81 | if ok { 82 | if n < rb.nsrc && !atEOF { 83 | err = transform.ErrShortSrc 84 | } 85 | return nDst, nSrc, err 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/proto/proto3_proto/proto3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto3"; 33 | 34 | import "google/protobuf/any.proto"; 35 | import "testdata/test.proto"; 36 | 37 | package proto3_proto; 38 | 39 | message Message { 40 | enum Humour { 41 | UNKNOWN = 0; 42 | PUNS = 1; 43 | SLAPSTICK = 2; 44 | BILL_BAILEY = 3; 45 | } 46 | 47 | string name = 1; 48 | Humour hilarity = 2; 49 | uint32 height_in_cm = 3; 50 | bytes data = 4; 51 | int64 result_count = 7; 52 | bool true_scotsman = 8; 53 | float score = 9; 54 | 55 | repeated uint64 key = 5; 56 | Nested nested = 6; 57 | repeated Humour r_funny = 16; 58 | 59 | map terrain = 10; 60 | testdata.SubDefaults proto2_field = 11; 61 | map proto2_value = 13; 62 | 63 | google.protobuf.Any anything = 14; 64 | repeated google.protobuf.Any many_things = 15; 65 | } 66 | 67 | message Nested { 68 | string bunny = 1; 69 | bool cute = 2; 70 | } 71 | 72 | message MessageWithMap { 73 | map byte_mapping = 1; 74 | } 75 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "net" 12 | "net/http" 13 | "time" 14 | ) 15 | 16 | type contextContext interface { 17 | Done() <-chan struct{} 18 | Err() error 19 | } 20 | 21 | type fakeContext struct{} 22 | 23 | func (fakeContext) Done() <-chan struct{} { return nil } 24 | func (fakeContext) Err() error { panic("should not be called") } 25 | 26 | func reqContext(r *http.Request) fakeContext { 27 | return fakeContext{} 28 | } 29 | 30 | func setResponseUncompressed(res *http.Response) { 31 | // Nothing. 32 | } 33 | 34 | type clientTrace struct{} 35 | 36 | func requestTrace(*http.Request) *clientTrace { return nil } 37 | func traceGotConn(*http.Request, *ClientConn) {} 38 | func traceFirstResponseByte(*clientTrace) {} 39 | func traceWroteHeaders(*clientTrace) {} 40 | func traceWroteRequest(*clientTrace, error) {} 41 | func traceGot100Continue(trace *clientTrace) {} 42 | func traceWait100Continue(trace *clientTrace) {} 43 | 44 | func nop() {} 45 | 46 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 47 | return nil, nop 48 | } 49 | 50 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 51 | return ctx, nop 52 | } 53 | 54 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 55 | return req 56 | } 57 | 58 | // temporary copy of Go 1.6's private tls.Config.clone: 59 | func cloneTLSConfig(c *tls.Config) *tls.Config { 60 | return &tls.Config{ 61 | Rand: c.Rand, 62 | Time: c.Time, 63 | Certificates: c.Certificates, 64 | NameToCertificate: c.NameToCertificate, 65 | GetCertificate: c.GetCertificate, 66 | RootCAs: c.RootCAs, 67 | NextProtos: c.NextProtos, 68 | ServerName: c.ServerName, 69 | ClientAuth: c.ClientAuth, 70 | ClientCAs: c.ClientCAs, 71 | InsecureSkipVerify: c.InsecureSkipVerify, 72 | CipherSuites: c.CipherSuites, 73 | PreferServerCipherSuites: c.PreferServerCipherSuites, 74 | SessionTicketsDisabled: c.SessionTicketsDisabled, 75 | SessionTicketKey: c.SessionTicketKey, 76 | ClientSessionCache: c.ClientSessionCache, 77 | MinVersion: c.MinVersion, 78 | MaxVersion: c.MaxVersion, 79 | CurvePreferences: c.CurvePreferences, 80 | } 81 | } 82 | 83 | func (cc *ClientConn) Ping(ctx contextContext) error { 84 | return cc.ping(ctx) 85 | } 86 | 87 | func (t *Transport) idleConnTimeout() time.Duration { return 0 } 88 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/go16.go: -------------------------------------------------------------------------------- 1 | // +build go1.6,!go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package grpc 22 | 23 | import ( 24 | "fmt" 25 | "io" 26 | "net" 27 | "net/http" 28 | "os" 29 | 30 | "golang.org/x/net/context" 31 | "google.golang.org/grpc/codes" 32 | "google.golang.org/grpc/status" 33 | "google.golang.org/grpc/transport" 34 | ) 35 | 36 | // dialContext connects to the address on the named network. 37 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 38 | return (&net.Dialer{Cancel: ctx.Done()}).Dial(network, address) 39 | } 40 | 41 | func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { 42 | req.Cancel = ctx.Done() 43 | if err := req.Write(conn); err != nil { 44 | return fmt.Errorf("failed to write the HTTP request: %v", err) 45 | } 46 | return nil 47 | } 48 | 49 | // toRPCErr converts an error into an error from the status package. 50 | func toRPCErr(err error) error { 51 | if _, ok := status.FromError(err); ok { 52 | return err 53 | } 54 | switch e := err.(type) { 55 | case transport.StreamError: 56 | return status.Error(e.Code, e.Desc) 57 | case transport.ConnectionError: 58 | return status.Error(codes.Unavailable, e.Desc) 59 | default: 60 | switch err { 61 | case context.DeadlineExceeded: 62 | return status.Error(codes.DeadlineExceeded, err.Error()) 63 | case context.Canceled: 64 | return status.Error(codes.Canceled, err.Error()) 65 | case ErrClientConnClosing: 66 | return status.Error(codes.FailedPrecondition, err.Error()) 67 | } 68 | } 69 | return status.Error(codes.Unknown, err.Error()) 70 | } 71 | 72 | // convertCode converts a standard Go error into its canonical code. Note that 73 | // this is only used to translate the error returned by the server applications. 74 | func convertCode(err error) codes.Code { 75 | switch err { 76 | case nil: 77 | return codes.OK 78 | case io.EOF: 79 | return codes.OutOfRange 80 | case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF: 81 | return codes.FailedPrecondition 82 | case os.ErrInvalid: 83 | return codes.InvalidArgument 84 | case context.Canceled: 85 | return codes.Canceled 86 | case context.DeadlineExceeded: 87 | return codes.DeadlineExceeded 88 | } 89 | switch { 90 | case os.IsExist(err): 91 | return codes.AlreadyExists 92 | case os.IsNotExist(err): 93 | return codes.NotFound 94 | case os.IsPermission(err): 95 | return codes.PermissionDenied 96 | } 97 | return codes.Unknown 98 | } 99 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package context 8 | 9 | import ( 10 | "context" // standard library's context, as of Go 1.7 11 | "time" 12 | ) 13 | 14 | var ( 15 | todo = context.TODO() 16 | background = context.Background() 17 | ) 18 | 19 | // Canceled is the error returned by Context.Err when the context is canceled. 20 | var Canceled = context.Canceled 21 | 22 | // DeadlineExceeded is the error returned by Context.Err when the context's 23 | // deadline passes. 24 | var DeadlineExceeded = context.DeadlineExceeded 25 | 26 | // WithCancel returns a copy of parent with a new Done channel. The returned 27 | // context's Done channel is closed when the returned cancel function is called 28 | // or when the parent context's Done channel is closed, whichever happens first. 29 | // 30 | // Canceling this context releases resources associated with it, so code should 31 | // call cancel as soon as the operations running in this Context complete. 32 | func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { 33 | ctx, f := context.WithCancel(parent) 34 | return ctx, CancelFunc(f) 35 | } 36 | 37 | // WithDeadline returns a copy of the parent context with the deadline adjusted 38 | // to be no later than d. If the parent's deadline is already earlier than d, 39 | // WithDeadline(parent, d) is semantically equivalent to parent. The returned 40 | // context's Done channel is closed when the deadline expires, when the returned 41 | // cancel function is called, or when the parent context's Done channel is 42 | // closed, whichever happens first. 43 | // 44 | // Canceling this context releases resources associated with it, so code should 45 | // call cancel as soon as the operations running in this Context complete. 46 | func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) { 47 | ctx, f := context.WithDeadline(parent, deadline) 48 | return ctx, CancelFunc(f) 49 | } 50 | 51 | // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). 52 | // 53 | // Canceling this context releases resources associated with it, so code should 54 | // call cancel as soon as the operations running in this Context complete: 55 | // 56 | // func slowOperationWithTimeout(ctx context.Context) (Result, error) { 57 | // ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) 58 | // defer cancel() // releases resources if slowOperation completes before timeout elapses 59 | // return slowOperation(ctx) 60 | // } 61 | func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) { 62 | return WithDeadline(parent, time.Now().Add(timeout)) 63 | } 64 | 65 | // WithValue returns a copy of parent in which the value associated with key is 66 | // val. 67 | // 68 | // Use context Values only for request-scoped data that transits processes and 69 | // APIs, not for passing optional parameters to functions. 70 | func WithValue(parent Context, key interface{}, val interface{}) Context { 71 | return context.WithValue(parent, key, val) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/backoff.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "math/rand" 23 | "time" 24 | ) 25 | 26 | // DefaultBackoffConfig uses values specified for backoff in 27 | // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md. 28 | var ( 29 | DefaultBackoffConfig = BackoffConfig{ 30 | MaxDelay: 120 * time.Second, 31 | baseDelay: 1.0 * time.Second, 32 | factor: 1.6, 33 | jitter: 0.2, 34 | } 35 | ) 36 | 37 | // backoffStrategy defines the methodology for backing off after a grpc 38 | // connection failure. 39 | // 40 | // This is unexported until the gRPC project decides whether or not to allow 41 | // alternative backoff strategies. Once a decision is made, this type and its 42 | // method may be exported. 43 | type backoffStrategy interface { 44 | // backoff returns the amount of time to wait before the next retry given 45 | // the number of consecutive failures. 46 | backoff(retries int) time.Duration 47 | } 48 | 49 | // BackoffConfig defines the parameters for the default gRPC backoff strategy. 50 | type BackoffConfig struct { 51 | // MaxDelay is the upper bound of backoff delay. 52 | MaxDelay time.Duration 53 | 54 | // TODO(stevvooe): The following fields are not exported, as allowing 55 | // changes would violate the current gRPC specification for backoff. If 56 | // gRPC decides to allow more interesting backoff strategies, these fields 57 | // may be opened up in the future. 58 | 59 | // baseDelay is the amount of time to wait before retrying after the first 60 | // failure. 61 | baseDelay time.Duration 62 | 63 | // factor is applied to the backoff after each retry. 64 | factor float64 65 | 66 | // jitter provides a range to randomize backoff delays. 67 | jitter float64 68 | } 69 | 70 | func setDefaults(bc *BackoffConfig) { 71 | md := bc.MaxDelay 72 | *bc = DefaultBackoffConfig 73 | 74 | if md > 0 { 75 | bc.MaxDelay = md 76 | } 77 | } 78 | 79 | func (bc BackoffConfig) backoff(retries int) time.Duration { 80 | if retries == 0 { 81 | return bc.baseDelay 82 | } 83 | backoff, max := float64(bc.baseDelay), float64(bc.MaxDelay) 84 | for backoff < max && retries > 0 { 85 | backoff *= bc.factor 86 | retries-- 87 | } 88 | if backoff > max { 89 | backoff = max 90 | } 91 | // Randomize backoff delays so that if a cluster of requests start at 92 | // the same time, they won't operate in lockstep. 93 | backoff *= 1 + bc.jitter*(rand.Float64()*2-1) 94 | if backoff < 0 { 95 | return 0 96 | } 97 | return time.Duration(backoff) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "context" 11 | "net" 12 | "net/http" 13 | "net/http/httptrace" 14 | "time" 15 | ) 16 | 17 | type contextContext interface { 18 | context.Context 19 | } 20 | 21 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 22 | ctx, cancel = context.WithCancel(context.Background()) 23 | ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr()) 24 | if hs := opts.baseConfig(); hs != nil { 25 | ctx = context.WithValue(ctx, http.ServerContextKey, hs) 26 | } 27 | return 28 | } 29 | 30 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 31 | return context.WithCancel(ctx) 32 | } 33 | 34 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 35 | return req.WithContext(ctx) 36 | } 37 | 38 | type clientTrace httptrace.ClientTrace 39 | 40 | func reqContext(r *http.Request) context.Context { return r.Context() } 41 | 42 | func (t *Transport) idleConnTimeout() time.Duration { 43 | if t.t1 != nil { 44 | return t.t1.IdleConnTimeout 45 | } 46 | return 0 47 | } 48 | 49 | func setResponseUncompressed(res *http.Response) { res.Uncompressed = true } 50 | 51 | func traceGotConn(req *http.Request, cc *ClientConn) { 52 | trace := httptrace.ContextClientTrace(req.Context()) 53 | if trace == nil || trace.GotConn == nil { 54 | return 55 | } 56 | ci := httptrace.GotConnInfo{Conn: cc.tconn} 57 | cc.mu.Lock() 58 | ci.Reused = cc.nextStreamID > 1 59 | ci.WasIdle = len(cc.streams) == 0 && ci.Reused 60 | if ci.WasIdle && !cc.lastActive.IsZero() { 61 | ci.IdleTime = time.Now().Sub(cc.lastActive) 62 | } 63 | cc.mu.Unlock() 64 | 65 | trace.GotConn(ci) 66 | } 67 | 68 | func traceWroteHeaders(trace *clientTrace) { 69 | if trace != nil && trace.WroteHeaders != nil { 70 | trace.WroteHeaders() 71 | } 72 | } 73 | 74 | func traceGot100Continue(trace *clientTrace) { 75 | if trace != nil && trace.Got100Continue != nil { 76 | trace.Got100Continue() 77 | } 78 | } 79 | 80 | func traceWait100Continue(trace *clientTrace) { 81 | if trace != nil && trace.Wait100Continue != nil { 82 | trace.Wait100Continue() 83 | } 84 | } 85 | 86 | func traceWroteRequest(trace *clientTrace, err error) { 87 | if trace != nil && trace.WroteRequest != nil { 88 | trace.WroteRequest(httptrace.WroteRequestInfo{Err: err}) 89 | } 90 | } 91 | 92 | func traceFirstResponseByte(trace *clientTrace) { 93 | if trace != nil && trace.GotFirstResponseByte != nil { 94 | trace.GotFirstResponseByte() 95 | } 96 | } 97 | 98 | func requestTrace(req *http.Request) *clientTrace { 99 | trace := httptrace.ContextClientTrace(req.Context()) 100 | return (*clientTrace)(trace) 101 | } 102 | 103 | // Ping sends a PING frame to the server and waits for the ack. 104 | func (cc *ClientConn) Ping(ctx context.Context) error { 105 | return cc.ping(ctx) 106 | } 107 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/trace.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "bytes" 23 | "fmt" 24 | "io" 25 | "net" 26 | "strings" 27 | "time" 28 | 29 | "golang.org/x/net/trace" 30 | ) 31 | 32 | // EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package. 33 | // This should only be set before any RPCs are sent or received by this program. 34 | var EnableTracing = true 35 | 36 | // methodFamily returns the trace family for the given method. 37 | // It turns "/pkg.Service/GetFoo" into "pkg.Service". 38 | func methodFamily(m string) string { 39 | m = strings.TrimPrefix(m, "/") // remove leading slash 40 | if i := strings.Index(m, "/"); i >= 0 { 41 | m = m[:i] // remove everything from second slash 42 | } 43 | if i := strings.LastIndex(m, "."); i >= 0 { 44 | m = m[i+1:] // cut down to last dotted component 45 | } 46 | return m 47 | } 48 | 49 | // traceInfo contains tracing information for an RPC. 50 | type traceInfo struct { 51 | tr trace.Trace 52 | firstLine firstLine 53 | } 54 | 55 | // firstLine is the first line of an RPC trace. 56 | type firstLine struct { 57 | client bool // whether this is a client (outgoing) RPC 58 | remoteAddr net.Addr 59 | deadline time.Duration // may be zero 60 | } 61 | 62 | func (f *firstLine) String() string { 63 | var line bytes.Buffer 64 | io.WriteString(&line, "RPC: ") 65 | if f.client { 66 | io.WriteString(&line, "to") 67 | } else { 68 | io.WriteString(&line, "from") 69 | } 70 | fmt.Fprintf(&line, " %v deadline:", f.remoteAddr) 71 | if f.deadline != 0 { 72 | fmt.Fprint(&line, f.deadline) 73 | } else { 74 | io.WriteString(&line, "none") 75 | } 76 | return line.String() 77 | } 78 | 79 | // payload represents an RPC request or response payload. 80 | type payload struct { 81 | sent bool // whether this is an outgoing payload 82 | msg interface{} // e.g. a proto.Message 83 | // TODO(dsymonds): add stringifying info to codec, and limit how much we hold here? 84 | } 85 | 86 | func (p payload) String() string { 87 | if p.sent { 88 | return fmt.Sprintf("sent: %v", p.msg) 89 | } 90 | return fmt.Sprintf("recv: %v", p.msg) 91 | } 92 | 93 | type fmtStringer struct { 94 | format string 95 | a []interface{} 96 | } 97 | 98 | func (f *fmtStringer) String() string { 99 | return fmt.Sprintf(f.format, f.a...) 100 | } 101 | 102 | type stringer string 103 | 104 | func (s stringer) String() string { return string(s) } 105 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | /* 4 | * 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package grpc 22 | 23 | import ( 24 | "context" 25 | "io" 26 | "net" 27 | "net/http" 28 | "os" 29 | 30 | netctx "golang.org/x/net/context" 31 | "google.golang.org/grpc/codes" 32 | "google.golang.org/grpc/status" 33 | "google.golang.org/grpc/transport" 34 | ) 35 | 36 | // dialContext connects to the address on the named network. 37 | func dialContext(ctx context.Context, network, address string) (net.Conn, error) { 38 | return (&net.Dialer{}).DialContext(ctx, network, address) 39 | } 40 | 41 | func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error { 42 | req = req.WithContext(ctx) 43 | if err := req.Write(conn); err != nil { 44 | return err 45 | } 46 | return nil 47 | } 48 | 49 | // toRPCErr converts an error into an error from the status package. 50 | func toRPCErr(err error) error { 51 | if _, ok := status.FromError(err); ok { 52 | return err 53 | } 54 | switch e := err.(type) { 55 | case transport.StreamError: 56 | return status.Error(e.Code, e.Desc) 57 | case transport.ConnectionError: 58 | return status.Error(codes.Unavailable, e.Desc) 59 | default: 60 | switch err { 61 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 62 | return status.Error(codes.DeadlineExceeded, err.Error()) 63 | case context.Canceled, netctx.Canceled: 64 | return status.Error(codes.Canceled, err.Error()) 65 | case ErrClientConnClosing: 66 | return status.Error(codes.FailedPrecondition, err.Error()) 67 | } 68 | } 69 | return status.Error(codes.Unknown, err.Error()) 70 | } 71 | 72 | // convertCode converts a standard Go error into its canonical code. Note that 73 | // this is only used to translate the error returned by the server applications. 74 | func convertCode(err error) codes.Code { 75 | switch err { 76 | case nil: 77 | return codes.OK 78 | case io.EOF: 79 | return codes.OutOfRange 80 | case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF: 81 | return codes.FailedPrecondition 82 | case os.ErrInvalid: 83 | return codes.InvalidArgument 84 | case context.Canceled, netctx.Canceled: 85 | return codes.Canceled 86 | case context.DeadlineExceeded, netctx.DeadlineExceeded: 87 | return codes.DeadlineExceeded 88 | } 89 | switch { 90 | case os.IsExist(err): 91 | return codes.AlreadyExists 92 | case os.IsNotExist(err): 93 | return codes.NotFound 94 | case os.IsPermission(err): 95 | return codes.PermissionDenied 96 | } 97 | return codes.Unknown 98 | } 99 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/codec.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "math" 23 | "sync" 24 | 25 | "github.com/golang/protobuf/proto" 26 | ) 27 | 28 | // Codec defines the interface gRPC uses to encode and decode messages. 29 | // Note that implementations of this interface must be thread safe; 30 | // a Codec's methods can be called from concurrent goroutines. 31 | type Codec interface { 32 | // Marshal returns the wire format of v. 33 | Marshal(v interface{}) ([]byte, error) 34 | // Unmarshal parses the wire format into v. 35 | Unmarshal(data []byte, v interface{}) error 36 | // String returns the name of the Codec implementation. The returned 37 | // string will be used as part of content type in transmission. 38 | String() string 39 | } 40 | 41 | // protoCodec is a Codec implementation with protobuf. It is the default codec for gRPC. 42 | type protoCodec struct { 43 | } 44 | 45 | type cachedProtoBuffer struct { 46 | lastMarshaledSize uint32 47 | proto.Buffer 48 | } 49 | 50 | func capToMaxInt32(val int) uint32 { 51 | if val > math.MaxInt32 { 52 | return uint32(math.MaxInt32) 53 | } 54 | return uint32(val) 55 | } 56 | 57 | func (p protoCodec) marshal(v interface{}, cb *cachedProtoBuffer) ([]byte, error) { 58 | protoMsg := v.(proto.Message) 59 | newSlice := make([]byte, 0, cb.lastMarshaledSize) 60 | 61 | cb.SetBuf(newSlice) 62 | cb.Reset() 63 | if err := cb.Marshal(protoMsg); err != nil { 64 | return nil, err 65 | } 66 | out := cb.Bytes() 67 | cb.lastMarshaledSize = capToMaxInt32(len(out)) 68 | return out, nil 69 | } 70 | 71 | func (p protoCodec) Marshal(v interface{}) ([]byte, error) { 72 | cb := protoBufferPool.Get().(*cachedProtoBuffer) 73 | out, err := p.marshal(v, cb) 74 | 75 | // put back buffer and lose the ref to the slice 76 | cb.SetBuf(nil) 77 | protoBufferPool.Put(cb) 78 | return out, err 79 | } 80 | 81 | func (p protoCodec) Unmarshal(data []byte, v interface{}) error { 82 | cb := protoBufferPool.Get().(*cachedProtoBuffer) 83 | cb.SetBuf(data) 84 | v.(proto.Message).Reset() 85 | err := cb.Unmarshal(v.(proto.Message)) 86 | cb.SetBuf(nil) 87 | protoBufferPool.Put(cb) 88 | return err 89 | } 90 | 91 | func (protoCodec) String() string { 92 | return "proto" 93 | } 94 | 95 | var ( 96 | protoBufferPool = &sync.Pool{ 97 | New: func() interface{} { 98 | return &cachedProtoBuffer{ 99 | Buffer: proto.Buffer{}, 100 | lastMarshaledSize: 16, 101 | } 102 | }, 103 | } 104 | ) 105 | -------------------------------------------------------------------------------- /server/server.go: -------------------------------------------------------------------------------- 1 | // server/server.go 2 | 3 | package server 4 | 5 | import ( 6 | "log" 7 | "sync" 8 | 9 | "google.golang.org/grpc/codes" 10 | "google.golang.org/grpc/status" 11 | 12 | oldctx "golang.org/x/net/context" 13 | 14 | api "github.com/iheanyi/grpc-phonebook/api" 15 | ) 16 | 17 | // Use in-memory DB for simplicity 18 | type server struct { 19 | contactsByNameMu sync.RWMutex 20 | contactsByName map[string]*api.Contact 21 | } 22 | 23 | func New() api.PhoneBookServer { 24 | contactsByName := make(map[string]*api.Contact) 25 | contactsByName["Iheanyi Ekechukwu"] = &api.Contact{ 26 | Name: "Iheanyi Ekechukwu", 27 | Email: "me@iheanyi.com", 28 | PhoneNumbers: []*api.PhoneNumber{ 29 | { 30 | Number: "123-456-7890", 31 | Type: api.PhoneNumber_HOME, 32 | }, 33 | }, 34 | Home: &api.PhoneNumber{ 35 | Number: "843-340-0830", 36 | Type: api.PhoneNumber_HOME, 37 | }, 38 | } 39 | 40 | return &server{ 41 | contactsByName: contactsByName, 42 | } 43 | } 44 | 45 | func (svc *server) CreateContact(ctx oldctx.Context, req *api.CreateContactReq) (*api.CreateContactRes, error) { 46 | log.Printf("Creating contact %v", req) 47 | if len(req.Name) == 0 { 48 | return nil, status.Errorf(codes.InvalidArgument, "name cannot be blank") 49 | } 50 | contact := &api.Contact{ 51 | Name: req.Name, 52 | Email: req.Email, 53 | PhoneNumbers: req.PhoneNumbers, 54 | Home: req.Home, 55 | Mobile: req.Mobile, 56 | Work: req.Work, 57 | } 58 | 59 | svc.contactsByName[contact.Name] = contact 60 | res := &api.CreateContactRes{ 61 | Contact: contact, 62 | } 63 | 64 | log.Printf("Done creating contact %v", contact) 65 | return res, nil 66 | } 67 | 68 | func (svc *server) ListContacts(ctx oldctx.Context, req *api.ListContactsReq) (*api.ListContactsRes, error) { 69 | var contacts []*api.Contact 70 | // We're going to map the keys to an array. 71 | for _, contact := range svc.contactsByName { 72 | contacts = append(contacts, contact) 73 | } 74 | 75 | res := &api.ListContactsRes{ 76 | Contacts: contacts, 77 | } 78 | 79 | return res, nil 80 | } 81 | 82 | func (svc *server) DeleteContact(ctx oldctx.Context, req *api.DeleteContactReq) (*api.DeleteContactRes, error) { 83 | svc.contactsByNameMu.Lock() 84 | defer svc.contactsByNameMu.Unlock() 85 | 86 | contact, ok := svc.contactsByName[req.Name] 87 | if !ok { 88 | return nil, api.ErrorNotFound 89 | } 90 | 91 | delete(svc.contactsByName, req.Name) 92 | res := &api.DeleteContactRes{ 93 | Contact: contact, 94 | } 95 | 96 | return res, nil 97 | } 98 | 99 | func (svc *server) ShowContact(ctx oldctx.Context, req *api.ShowContactReq) (*api.ShowContactRes, error) { 100 | svc.contactsByNameMu.RLock() 101 | defer svc.contactsByNameMu.RUnlock() 102 | 103 | contact, ok := svc.contactsByName[req.Name] 104 | if !ok { 105 | return nil, api.ErrorNotFound 106 | } 107 | 108 | res := &api.ShowContactRes{ 109 | Contact: contact, 110 | } 111 | 112 | return res, nil 113 | } 114 | 115 | func (svc *server) UpdateContact(ctx oldctx.Context, req *api.UpdateContactReq) (*api.UpdateContactRes, error) { 116 | return nil, status.Errorf(codes.Unimplemented, "not implemented") 117 | } 118 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/readwriter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "io" 8 | 9 | type normWriter struct { 10 | rb reorderBuffer 11 | w io.Writer 12 | buf []byte 13 | } 14 | 15 | // Write implements the standard write interface. If the last characters are 16 | // not at a normalization boundary, the bytes will be buffered for the next 17 | // write. The remaining bytes will be written on close. 18 | func (w *normWriter) Write(data []byte) (n int, err error) { 19 | // Process data in pieces to keep w.buf size bounded. 20 | const chunk = 4000 21 | 22 | for len(data) > 0 { 23 | // Normalize into w.buf. 24 | m := len(data) 25 | if m > chunk { 26 | m = chunk 27 | } 28 | w.rb.src = inputBytes(data[:m]) 29 | w.rb.nsrc = m 30 | w.buf = doAppend(&w.rb, w.buf, 0) 31 | data = data[m:] 32 | n += m 33 | 34 | // Write out complete prefix, save remainder. 35 | // Note that lastBoundary looks back at most 31 runes. 36 | i := lastBoundary(&w.rb.f, w.buf) 37 | if i == -1 { 38 | i = 0 39 | } 40 | if i > 0 { 41 | if _, err = w.w.Write(w.buf[:i]); err != nil { 42 | break 43 | } 44 | bn := copy(w.buf, w.buf[i:]) 45 | w.buf = w.buf[:bn] 46 | } 47 | } 48 | return n, err 49 | } 50 | 51 | // Close forces data that remains in the buffer to be written. 52 | func (w *normWriter) Close() error { 53 | if len(w.buf) > 0 { 54 | _, err := w.w.Write(w.buf) 55 | if err != nil { 56 | return err 57 | } 58 | } 59 | return nil 60 | } 61 | 62 | // Writer returns a new writer that implements Write(b) 63 | // by writing f(b) to w. The returned writer may use an 64 | // an internal buffer to maintain state across Write calls. 65 | // Calling its Close method writes any buffered data to w. 66 | func (f Form) Writer(w io.Writer) io.WriteCloser { 67 | wr := &normWriter{rb: reorderBuffer{}, w: w} 68 | wr.rb.init(f, nil) 69 | return wr 70 | } 71 | 72 | type normReader struct { 73 | rb reorderBuffer 74 | r io.Reader 75 | inbuf []byte 76 | outbuf []byte 77 | bufStart int 78 | lastBoundary int 79 | err error 80 | } 81 | 82 | // Read implements the standard read interface. 83 | func (r *normReader) Read(p []byte) (int, error) { 84 | for { 85 | if r.lastBoundary-r.bufStart > 0 { 86 | n := copy(p, r.outbuf[r.bufStart:r.lastBoundary]) 87 | r.bufStart += n 88 | if r.lastBoundary-r.bufStart > 0 { 89 | return n, nil 90 | } 91 | return n, r.err 92 | } 93 | if r.err != nil { 94 | return 0, r.err 95 | } 96 | outn := copy(r.outbuf, r.outbuf[r.lastBoundary:]) 97 | r.outbuf = r.outbuf[0:outn] 98 | r.bufStart = 0 99 | 100 | n, err := r.r.Read(r.inbuf) 101 | r.rb.src = inputBytes(r.inbuf[0:n]) 102 | r.rb.nsrc, r.err = n, err 103 | if n > 0 { 104 | r.outbuf = doAppend(&r.rb, r.outbuf, 0) 105 | } 106 | if err == io.EOF { 107 | r.lastBoundary = len(r.outbuf) 108 | } else { 109 | r.lastBoundary = lastBoundary(&r.rb.f, r.outbuf) 110 | if r.lastBoundary == -1 { 111 | r.lastBoundary = 0 112 | } 113 | } 114 | } 115 | } 116 | 117 | // Reader returns a new reader that implements Read 118 | // by reading data from r and returning f(data). 119 | func (f Form) Reader(r io.Reader) io.Reader { 120 | const chunk = 4000 121 | buf := make([]byte, chunk) 122 | rr := &normReader{rb: reorderBuffer{}, r: r, inbuf: buf} 123 | rr.rb.init(f, buf) 124 | return rr 125 | } 126 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/keepalive/keepalive.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package keepalive defines configurable parameters for point-to-point healthcheck. 20 | package keepalive 21 | 22 | import ( 23 | "time" 24 | ) 25 | 26 | // ClientParameters is used to set keepalive parameters on the client-side. 27 | // These configure how the client will actively probe to notice when a connection is broken 28 | // and send pings so intermediaries will be aware of the liveness of the connection. 29 | // Make sure these parameters are set in coordination with the keepalive policy on the server, 30 | // as incompatible settings can result in closing of connection. 31 | type ClientParameters struct { 32 | // After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive. 33 | Time time.Duration // The current default value is infinity. 34 | // After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that 35 | // the connection is closed. 36 | Timeout time.Duration // The current default value is 20 seconds. 37 | // If true, client runs keepalive checks even with no active RPCs. 38 | PermitWithoutStream bool // false by default. 39 | } 40 | 41 | // ServerParameters is used to set keepalive and max-age parameters on the server-side. 42 | type ServerParameters struct { 43 | // MaxConnectionIdle is a duration for the amount of time after which an idle connection would be closed by sending a GoAway. 44 | // Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment. 45 | MaxConnectionIdle time.Duration // The current default value is infinity. 46 | // MaxConnectionAge is a duration for the maximum amount of time a connection may exist before it will be closed by sending a GoAway. 47 | // A random jitter of +/-10% will be added to MaxConnectionAge to spread out connection storms. 48 | MaxConnectionAge time.Duration // The current default value is infinity. 49 | // MaxConnectinoAgeGrace is an additive period after MaxConnectionAge after which the connection will be forcibly closed. 50 | MaxConnectionAgeGrace time.Duration // The current default value is infinity. 51 | // After a duration of this time if the server doesn't see any activity it pings the client to see if the transport is still alive. 52 | Time time.Duration // The current default value is 2 hours. 53 | // After having pinged for keepalive check, the server waits for a duration of Timeout and if no activity is seen even after that 54 | // the connection is closed. 55 | Timeout time.Duration // The current default value is 20 seconds. 56 | } 57 | 58 | // EnforcementPolicy is used to set keepalive enforcement policy on the server-side. 59 | // Server will close connection with a client that violates this policy. 60 | type EnforcementPolicy struct { 61 | // MinTime is the minimum amount of time a client should wait before sending a keepalive ping. 62 | MinTime time.Duration // The current default value is 5 minutes. 63 | // If true, server expects keepalive pings even when there are no active streams(RPCs). 64 | PermitWithoutStream bool // false by default. 65 | } 66 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/gotrack.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Defensive debug-only utility to track that functions run on the 6 | // goroutine that they're supposed to. 7 | 8 | package http2 9 | 10 | import ( 11 | "bytes" 12 | "errors" 13 | "fmt" 14 | "os" 15 | "runtime" 16 | "strconv" 17 | "sync" 18 | ) 19 | 20 | var DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1" 21 | 22 | type goroutineLock uint64 23 | 24 | func newGoroutineLock() goroutineLock { 25 | if !DebugGoroutines { 26 | return 0 27 | } 28 | return goroutineLock(curGoroutineID()) 29 | } 30 | 31 | func (g goroutineLock) check() { 32 | if !DebugGoroutines { 33 | return 34 | } 35 | if curGoroutineID() != uint64(g) { 36 | panic("running on the wrong goroutine") 37 | } 38 | } 39 | 40 | func (g goroutineLock) checkNotOn() { 41 | if !DebugGoroutines { 42 | return 43 | } 44 | if curGoroutineID() == uint64(g) { 45 | panic("running on the wrong goroutine") 46 | } 47 | } 48 | 49 | var goroutineSpace = []byte("goroutine ") 50 | 51 | func curGoroutineID() uint64 { 52 | bp := littleBuf.Get().(*[]byte) 53 | defer littleBuf.Put(bp) 54 | b := *bp 55 | b = b[:runtime.Stack(b, false)] 56 | // Parse the 4707 out of "goroutine 4707 [" 57 | b = bytes.TrimPrefix(b, goroutineSpace) 58 | i := bytes.IndexByte(b, ' ') 59 | if i < 0 { 60 | panic(fmt.Sprintf("No space found in %q", b)) 61 | } 62 | b = b[:i] 63 | n, err := parseUintBytes(b, 10, 64) 64 | if err != nil { 65 | panic(fmt.Sprintf("Failed to parse goroutine ID out of %q: %v", b, err)) 66 | } 67 | return n 68 | } 69 | 70 | var littleBuf = sync.Pool{ 71 | New: func() interface{} { 72 | buf := make([]byte, 64) 73 | return &buf 74 | }, 75 | } 76 | 77 | // parseUintBytes is like strconv.ParseUint, but using a []byte. 78 | func parseUintBytes(s []byte, base int, bitSize int) (n uint64, err error) { 79 | var cutoff, maxVal uint64 80 | 81 | if bitSize == 0 { 82 | bitSize = int(strconv.IntSize) 83 | } 84 | 85 | s0 := s 86 | switch { 87 | case len(s) < 1: 88 | err = strconv.ErrSyntax 89 | goto Error 90 | 91 | case 2 <= base && base <= 36: 92 | // valid base; nothing to do 93 | 94 | case base == 0: 95 | // Look for octal, hex prefix. 96 | switch { 97 | case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'): 98 | base = 16 99 | s = s[2:] 100 | if len(s) < 1 { 101 | err = strconv.ErrSyntax 102 | goto Error 103 | } 104 | case s[0] == '0': 105 | base = 8 106 | default: 107 | base = 10 108 | } 109 | 110 | default: 111 | err = errors.New("invalid base " + strconv.Itoa(base)) 112 | goto Error 113 | } 114 | 115 | n = 0 116 | cutoff = cutoff64(base) 117 | maxVal = 1<= base { 135 | n = 0 136 | err = strconv.ErrSyntax 137 | goto Error 138 | } 139 | 140 | if n >= cutoff { 141 | // n*base overflows 142 | n = 1<<64 - 1 143 | err = strconv.ErrRange 144 | goto Error 145 | } 146 | n *= uint64(base) 147 | 148 | n1 := n + uint64(v) 149 | if n1 < n || n1 > maxVal { 150 | // n+v overflows 151 | n = 1<<64 - 1 152 | err = strconv.ErrRange 153 | goto Error 154 | } 155 | n = n1 156 | } 157 | 158 | return n, nil 159 | 160 | Error: 161 | return n, &strconv.NumError{Func: "ParseUint", Num: string(s0), Err: err} 162 | } 163 | 164 | // Return the first number n such that n*base >= 1<<64. 165 | func cutoff64(base int) uint64 { 166 | if base < 2 { 167 | return 0 168 | } 169 | return (1<<64-1)/uint64(base) + 1 170 | } 171 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/interceptor.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2016 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "golang.org/x/net/context" 23 | ) 24 | 25 | // UnaryInvoker is called by UnaryClientInterceptor to complete RPCs. 26 | type UnaryInvoker func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, opts ...CallOption) error 27 | 28 | // UnaryClientInterceptor intercepts the execution of a unary RPC on the client. invoker is the handler to complete the RPC 29 | // and it is the responsibility of the interceptor to call it. 30 | // This is an EXPERIMENTAL API. 31 | type UnaryClientInterceptor func(ctx context.Context, method string, req, reply interface{}, cc *ClientConn, invoker UnaryInvoker, opts ...CallOption) error 32 | 33 | // Streamer is called by StreamClientInterceptor to create a ClientStream. 34 | type Streamer func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, opts ...CallOption) (ClientStream, error) 35 | 36 | // StreamClientInterceptor intercepts the creation of ClientStream. It may return a custom ClientStream to intercept all I/O 37 | // operations. streamer is the handler to create a ClientStream and it is the responsibility of the interceptor to call it. 38 | // This is an EXPERIMENTAL API. 39 | type StreamClientInterceptor func(ctx context.Context, desc *StreamDesc, cc *ClientConn, method string, streamer Streamer, opts ...CallOption) (ClientStream, error) 40 | 41 | // UnaryServerInfo consists of various information about a unary RPC on 42 | // server side. All per-rpc information may be mutated by the interceptor. 43 | type UnaryServerInfo struct { 44 | // Server is the service implementation the user provides. This is read-only. 45 | Server interface{} 46 | // FullMethod is the full RPC method string, i.e., /package.service/method. 47 | FullMethod string 48 | } 49 | 50 | // UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal 51 | // execution of a unary RPC. 52 | type UnaryHandler func(ctx context.Context, req interface{}) (interface{}, error) 53 | 54 | // UnaryServerInterceptor provides a hook to intercept the execution of a unary RPC on the server. info 55 | // contains all the information of this RPC the interceptor can operate on. And handler is the wrapper 56 | // of the service method implementation. It is the responsibility of the interceptor to invoke handler 57 | // to complete the RPC. 58 | type UnaryServerInterceptor func(ctx context.Context, req interface{}, info *UnaryServerInfo, handler UnaryHandler) (resp interface{}, err error) 59 | 60 | // StreamServerInfo consists of various information about a streaming RPC on 61 | // server side. All per-rpc information may be mutated by the interceptor. 62 | type StreamServerInfo struct { 63 | // FullMethod is the full RPC method string, i.e., /package.service/method. 64 | FullMethod string 65 | // IsClientStream indicates whether the RPC is a client streaming RPC. 66 | IsClientStream bool 67 | // IsServerStream indicates whether the RPC is a server streaming RPC. 68 | IsServerStream bool 69 | } 70 | 71 | // StreamServerInterceptor provides a hook to intercept the execution of a streaming RPC on the server. 72 | // info contains all the information of this RPC the interceptor can operate on. And handler is the 73 | // service method implementation. It is the responsibility of the interceptor to invoke handler to 74 | // complete the RPC. 75 | type StreamServerInterceptor func(srv interface{}, ss ServerStream, info *StreamServerInfo, handler StreamHandler) error 76 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/proxy.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "bufio" 23 | "errors" 24 | "fmt" 25 | "io" 26 | "net" 27 | "net/http" 28 | "net/http/httputil" 29 | "net/url" 30 | 31 | "golang.org/x/net/context" 32 | ) 33 | 34 | var ( 35 | // errDisabled indicates that proxy is disabled for the address. 36 | errDisabled = errors.New("proxy is disabled for the address") 37 | // The following variable will be overwritten in the tests. 38 | httpProxyFromEnvironment = http.ProxyFromEnvironment 39 | ) 40 | 41 | func mapAddress(ctx context.Context, address string) (string, error) { 42 | req := &http.Request{ 43 | URL: &url.URL{ 44 | Scheme: "https", 45 | Host: address, 46 | }, 47 | } 48 | url, err := httpProxyFromEnvironment(req) 49 | if err != nil { 50 | return "", err 51 | } 52 | if url == nil { 53 | return "", errDisabled 54 | } 55 | return url.Host, nil 56 | } 57 | 58 | // To read a response from a net.Conn, http.ReadResponse() takes a bufio.Reader. 59 | // It's possible that this reader reads more than what's need for the response and stores 60 | // those bytes in the buffer. 61 | // bufConn wraps the original net.Conn and the bufio.Reader to make sure we don't lose the 62 | // bytes in the buffer. 63 | type bufConn struct { 64 | net.Conn 65 | r io.Reader 66 | } 67 | 68 | func (c *bufConn) Read(b []byte) (int, error) { 69 | return c.r.Read(b) 70 | } 71 | 72 | func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, addr string) (_ net.Conn, err error) { 73 | defer func() { 74 | if err != nil { 75 | conn.Close() 76 | } 77 | }() 78 | 79 | req := (&http.Request{ 80 | Method: http.MethodConnect, 81 | URL: &url.URL{Host: addr}, 82 | Header: map[string][]string{"User-Agent": {grpcUA}}, 83 | }) 84 | 85 | if err := sendHTTPRequest(ctx, req, conn); err != nil { 86 | return nil, fmt.Errorf("failed to write the HTTP request: %v", err) 87 | } 88 | 89 | r := bufio.NewReader(conn) 90 | resp, err := http.ReadResponse(r, req) 91 | if err != nil { 92 | return nil, fmt.Errorf("reading server HTTP response: %v", err) 93 | } 94 | defer resp.Body.Close() 95 | if resp.StatusCode != http.StatusOK { 96 | dump, err := httputil.DumpResponse(resp, true) 97 | if err != nil { 98 | return nil, fmt.Errorf("failed to do connect handshake, status code: %s", resp.Status) 99 | } 100 | return nil, fmt.Errorf("failed to do connect handshake, response: %q", dump) 101 | } 102 | 103 | return &bufConn{Conn: conn, r: r}, nil 104 | } 105 | 106 | // newProxyDialer returns a dialer that connects to proxy first if necessary. 107 | // The returned dialer checks if a proxy is necessary, dial to the proxy with the 108 | // provided dialer, does HTTP CONNECT handshake and returns the connection. 109 | func newProxyDialer(dialer func(context.Context, string) (net.Conn, error)) func(context.Context, string) (net.Conn, error) { 110 | return func(ctx context.Context, addr string) (conn net.Conn, err error) { 111 | var skipHandshake bool 112 | newAddr, err := mapAddress(ctx, addr) 113 | if err != nil { 114 | if err != errDisabled { 115 | return nil, err 116 | } 117 | skipHandshake = true 118 | newAddr = addr 119 | } 120 | 121 | conn, err = dialer(ctx, newAddr) 122 | if err != nil { 123 | return 124 | } 125 | if !skipHandshake { 126 | conn, err = doHTTPConnectHandshake(ctx, conn, addr) 127 | } 128 | return 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/grpclog/grpclog.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package grpclog defines logging for grpc. 20 | // 21 | // All logs in transport package only go to verbose level 2. 22 | // All logs in other packages in grpc are logged in spite of the verbosity level. 23 | // 24 | // In the default logger, 25 | // severity level can be set by environment variable GRPC_GO_LOG_SEVERITY_LEVEL, 26 | // verbosity level can be set by GRPC_GO_LOG_VERBOSITY_LEVEL. 27 | package grpclog // import "google.golang.org/grpc/grpclog" 28 | 29 | import "os" 30 | 31 | var logger = newLoggerV2() 32 | 33 | // V reports whether verbosity level l is at least the requested verbose level. 34 | func V(l int) bool { 35 | return logger.V(l) 36 | } 37 | 38 | // Info logs to the INFO log. 39 | func Info(args ...interface{}) { 40 | logger.Info(args...) 41 | } 42 | 43 | // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf. 44 | func Infof(format string, args ...interface{}) { 45 | logger.Infof(format, args...) 46 | } 47 | 48 | // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println. 49 | func Infoln(args ...interface{}) { 50 | logger.Infoln(args...) 51 | } 52 | 53 | // Warning logs to the WARNING log. 54 | func Warning(args ...interface{}) { 55 | logger.Warning(args...) 56 | } 57 | 58 | // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf. 59 | func Warningf(format string, args ...interface{}) { 60 | logger.Warningf(format, args...) 61 | } 62 | 63 | // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println. 64 | func Warningln(args ...interface{}) { 65 | logger.Warningln(args...) 66 | } 67 | 68 | // Error logs to the ERROR log. 69 | func Error(args ...interface{}) { 70 | logger.Error(args...) 71 | } 72 | 73 | // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf. 74 | func Errorf(format string, args ...interface{}) { 75 | logger.Errorf(format, args...) 76 | } 77 | 78 | // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println. 79 | func Errorln(args ...interface{}) { 80 | logger.Errorln(args...) 81 | } 82 | 83 | // Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print. 84 | // It calls os.Exit() with exit code 1. 85 | func Fatal(args ...interface{}) { 86 | logger.Fatal(args...) 87 | // Make sure fatal logs will exit. 88 | os.Exit(1) 89 | } 90 | 91 | // Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf. 92 | // It calles os.Exit() with exit code 1. 93 | func Fatalf(format string, args ...interface{}) { 94 | logger.Fatalf(format, args...) 95 | // Make sure fatal logs will exit. 96 | os.Exit(1) 97 | } 98 | 99 | // Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println. 100 | // It calle os.Exit()) with exit code 1. 101 | func Fatalln(args ...interface{}) { 102 | logger.Fatalln(args...) 103 | // Make sure fatal logs will exit. 104 | os.Exit(1) 105 | } 106 | 107 | // Print prints to the logger. Arguments are handled in the manner of fmt.Print. 108 | // Deprecated: use Info. 109 | func Print(args ...interface{}) { 110 | logger.Info(args...) 111 | } 112 | 113 | // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf. 114 | // Deprecated: use Infof. 115 | func Printf(format string, args ...interface{}) { 116 | logger.Infof(format, args...) 117 | } 118 | 119 | // Println prints to the logger. Arguments are handled in the manner of fmt.Println. 120 | // Deprecated: use Infoln. 121 | func Println(args ...interface{}) { 122 | logger.Infoln(args...) 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/duration.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package ptypes 33 | 34 | // This file implements conversions between google.protobuf.Duration 35 | // and time.Duration. 36 | 37 | import ( 38 | "errors" 39 | "fmt" 40 | "time" 41 | 42 | durpb "github.com/golang/protobuf/ptypes/duration" 43 | ) 44 | 45 | const ( 46 | // Range of a durpb.Duration in seconds, as specified in 47 | // google/protobuf/duration.proto. This is about 10,000 years in seconds. 48 | maxSeconds = int64(10000 * 365.25 * 24 * 60 * 60) 49 | minSeconds = -maxSeconds 50 | ) 51 | 52 | // validateDuration determines whether the durpb.Duration is valid according to the 53 | // definition in google/protobuf/duration.proto. A valid durpb.Duration 54 | // may still be too large to fit into a time.Duration (the range of durpb.Duration 55 | // is about 10,000 years, and the range of time.Duration is about 290). 56 | func validateDuration(d *durpb.Duration) error { 57 | if d == nil { 58 | return errors.New("duration: nil Duration") 59 | } 60 | if d.Seconds < minSeconds || d.Seconds > maxSeconds { 61 | return fmt.Errorf("duration: %v: seconds out of range", d) 62 | } 63 | if d.Nanos <= -1e9 || d.Nanos >= 1e9 { 64 | return fmt.Errorf("duration: %v: nanos out of range", d) 65 | } 66 | // Seconds and Nanos must have the same sign, unless d.Nanos is zero. 67 | if (d.Seconds < 0 && d.Nanos > 0) || (d.Seconds > 0 && d.Nanos < 0) { 68 | return fmt.Errorf("duration: %v: seconds and nanos have different signs", d) 69 | } 70 | return nil 71 | } 72 | 73 | // Duration converts a durpb.Duration to a time.Duration. Duration 74 | // returns an error if the durpb.Duration is invalid or is too large to be 75 | // represented in a time.Duration. 76 | func Duration(p *durpb.Duration) (time.Duration, error) { 77 | if err := validateDuration(p); err != nil { 78 | return 0, err 79 | } 80 | d := time.Duration(p.Seconds) * time.Second 81 | if int64(d/time.Second) != p.Seconds { 82 | return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p) 83 | } 84 | if p.Nanos != 0 { 85 | d += time.Duration(p.Nanos) 86 | if (d < 0) != (p.Nanos < 0) { 87 | return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p) 88 | } 89 | } 90 | return d, nil 91 | } 92 | 93 | // DurationProto converts a time.Duration to a durpb.Duration. 94 | func DurationProto(d time.Duration) *durpb.Duration { 95 | nanos := d.Nanoseconds() 96 | secs := nanos / 1e9 97 | nanos -= secs * 1e9 98 | return &durpb.Duration{ 99 | Seconds: secs, 100 | Nanos: int32(nanos), 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/duration/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/duration"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "DurationProto"; 39 | option java_multiple_files = true; 40 | option java_generate_equals_and_hash = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Duration represents a signed, fixed-length span of time represented 44 | // as a count of seconds and fractions of seconds at nanosecond 45 | // resolution. It is independent of any calendar and concepts like "day" 46 | // or "month". It is related to Timestamp in that the difference between 47 | // two Timestamp values is a Duration and it can be added or subtracted 48 | // from a Timestamp. Range is approximately +-10,000 years. 49 | // 50 | // Example 1: Compute Duration from two Timestamps in pseudo code. 51 | // 52 | // Timestamp start = ...; 53 | // Timestamp end = ...; 54 | // Duration duration = ...; 55 | // 56 | // duration.seconds = end.seconds - start.seconds; 57 | // duration.nanos = end.nanos - start.nanos; 58 | // 59 | // if (duration.seconds < 0 && duration.nanos > 0) { 60 | // duration.seconds += 1; 61 | // duration.nanos -= 1000000000; 62 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 63 | // duration.seconds -= 1; 64 | // duration.nanos += 1000000000; 65 | // } 66 | // 67 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 68 | // 69 | // Timestamp start = ...; 70 | // Duration duration = ...; 71 | // Timestamp end = ...; 72 | // 73 | // end.seconds = start.seconds + duration.seconds; 74 | // end.nanos = start.nanos + duration.nanos; 75 | // 76 | // if (end.nanos < 0) { 77 | // end.seconds -= 1; 78 | // end.nanos += 1000000000; 79 | // } else if (end.nanos >= 1000000000) { 80 | // end.seconds += 1; 81 | // end.nanos -= 1000000000; 82 | // } 83 | // 84 | // 85 | message Duration { 86 | 87 | // Signed seconds of the span of time. Must be from -315,576,000,000 88 | // to +315,576,000,000 inclusive. 89 | int64 seconds = 1; 90 | 91 | // Signed fractions of a second at nanosecond resolution of the span 92 | // of time. Durations less than one second are represented with a 0 93 | // `seconds` field and a positive or negative `nanos` field. For durations 94 | // of one second or more, a non-zero value for the `nanos` field must be 95 | // of the same sign as the `seconds` field. Must be from -999,999,999 96 | // to +999,999,999 inclusive. 97 | int32 nanos = 2; 98 | } 99 | -------------------------------------------------------------------------------- /cmd/pbctl/pbctl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // cmd/pbctl/pbctl 3 | var PROTO_PATH = __dirname + '/../../api/api.proto'; 4 | var grpc = require('grpc'); 5 | var program = require('commander'); 6 | var path = require('path'); 7 | var api = grpc.load(path.resolve(PROTO_PATH)).api; 8 | var client = new api.PhoneBook('localhost:50051', grpc.credentials.createInsecure()); 9 | require('console.table'); 10 | 11 | var PhoneType = api.PhoneNumber.PhoneType; 12 | 13 | const VERSION = '0.0.1'; 14 | 15 | function phoneNumberArr(val, numbers) { 16 | numbers.push(val); 17 | return numbers; 18 | } 19 | 20 | function listContacts() { 21 | var request = new api.ListContactsReq(); 22 | client.listContacts(request, function(err, response) { 23 | if (err) { 24 | console.error(err.message); 25 | return; 26 | } 27 | 28 | printContacts(formatContacts(response.contacts)); 29 | }); 30 | } 31 | 32 | function printHeader() { 33 | console.log("Name\t\tEmail\t\tHome\t\tMobile\t\tWork\t\t"); 34 | } 35 | 36 | function formatContacts(contacts) { 37 | return contacts.map(function(contact) { 38 | newContact = contact; 39 | newContact.home = contact.home && contact.home.number || ''; 40 | newContact.mobile = contact.mobile && contact.mobile.number || ''; 41 | newContact.work = contact.work && contact.work.number || ''; 42 | delete newContact.phone_numbers; 43 | 44 | return newContact; 45 | }); 46 | } 47 | 48 | function printContacts(contacts) { 49 | if (contacts.length === 0) { 50 | console.log("No contacts exist"); 51 | return; 52 | } 53 | console.table(contacts); 54 | } 55 | 56 | function printContact(contact) { 57 | console.log(tabItem(contact.name) + tabItem(contact.email)); 58 | } 59 | 60 | function tabItem(value) { 61 | return value + "\t\t"; 62 | } 63 | 64 | program 65 | .version(VERSION) 66 | 67 | program 68 | .command('create ') 69 | .option('-n, --name ', "Contact's name") 70 | .option('-e, --email ', "Contact's email") 71 | .option('-h, --home ', "Contact's home number") 72 | .option('-m, --mobile ', "Contact's mobile number") 73 | .option('-w, --work ', "Contact's work number") 74 | .action(function(name, options) { 75 | var request = new api.CreateContactReq(); 76 | var phoneArr = []; 77 | 78 | if (options.home) { 79 | var homeNum = new api.PhoneNumber(); 80 | homeNum.type = PhoneType.HOME; 81 | homeNum.number = options.home; 82 | phoneArr.push(homeNum); 83 | request.home = homeNum; 84 | } 85 | 86 | if (options.work) { 87 | var workNum = new api.PhoneNumber(); 88 | workNum.type = PhoneType.WORK; 89 | workNum.number = options.work; 90 | phoneArr.push(workNum); 91 | request.work = workNum; 92 | } 93 | 94 | if (options.mobile) { 95 | var mobileNum = new api.PhoneNumber(); 96 | mobileNum.type = PhoneType.MOBILE; 97 | mobileNum.number = options.work; 98 | phoneArr.push(mobileNum); 99 | request.mobile = mobileNum; 100 | } 101 | 102 | request.name = name; 103 | request.email = options.email || ''; 104 | request.phone_numbers = phoneArr; 105 | 106 | client.createContact(request, function(err, response) { 107 | if (err) { 108 | console.error(err.message); 109 | return; 110 | } 111 | 112 | printContacts(formatContacts([response.contact])); 113 | }); 114 | }); 115 | 116 | program 117 | .command('list') 118 | .action(function() { 119 | listContacts(); 120 | }); 121 | 122 | program 123 | .command('show ') 124 | .action(function(name) { 125 | var request = new api.ShowContactReq(); 126 | request.name = name; 127 | client.showContact(request, function(err, response) { 128 | if (err) { 129 | console.error(err.message); 130 | return; 131 | } 132 | 133 | printContacts(formatContacts([response.contact])); 134 | }); 135 | }); 136 | 137 | program 138 | .command('delete ') 139 | .action(function(name) { 140 | var request = new api.DeleteContactReq(); 141 | request.name = name; 142 | client.deleteContact(request, function(err, response) { 143 | if (err) { 144 | console.error(err.message); 145 | return; 146 | } 147 | 148 | listContacts(); 149 | }); 150 | }); 151 | 152 | program.parse(process.argv); 153 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/pre_go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.9 6 | 7 | package context 8 | 9 | import "time" 10 | 11 | // A Context carries a deadline, a cancelation signal, and other values across 12 | // API boundaries. 13 | // 14 | // Context's methods may be called by multiple goroutines simultaneously. 15 | type Context interface { 16 | // Deadline returns the time when work done on behalf of this context 17 | // should be canceled. Deadline returns ok==false when no deadline is 18 | // set. Successive calls to Deadline return the same results. 19 | Deadline() (deadline time.Time, ok bool) 20 | 21 | // Done returns a channel that's closed when work done on behalf of this 22 | // context should be canceled. Done may return nil if this context can 23 | // never be canceled. Successive calls to Done return the same value. 24 | // 25 | // WithCancel arranges for Done to be closed when cancel is called; 26 | // WithDeadline arranges for Done to be closed when the deadline 27 | // expires; WithTimeout arranges for Done to be closed when the timeout 28 | // elapses. 29 | // 30 | // Done is provided for use in select statements: 31 | // 32 | // // Stream generates values with DoSomething and sends them to out 33 | // // until DoSomething returns an error or ctx.Done is closed. 34 | // func Stream(ctx context.Context, out chan<- Value) error { 35 | // for { 36 | // v, err := DoSomething(ctx) 37 | // if err != nil { 38 | // return err 39 | // } 40 | // select { 41 | // case <-ctx.Done(): 42 | // return ctx.Err() 43 | // case out <- v: 44 | // } 45 | // } 46 | // } 47 | // 48 | // See http://blog.golang.org/pipelines for more examples of how to use 49 | // a Done channel for cancelation. 50 | Done() <-chan struct{} 51 | 52 | // Err returns a non-nil error value after Done is closed. Err returns 53 | // Canceled if the context was canceled or DeadlineExceeded if the 54 | // context's deadline passed. No other values for Err are defined. 55 | // After Done is closed, successive calls to Err return the same value. 56 | Err() error 57 | 58 | // Value returns the value associated with this context for key, or nil 59 | // if no value is associated with key. Successive calls to Value with 60 | // the same key returns the same result. 61 | // 62 | // Use context values only for request-scoped data that transits 63 | // processes and API boundaries, not for passing optional parameters to 64 | // functions. 65 | // 66 | // A key identifies a specific value in a Context. Functions that wish 67 | // to store values in Context typically allocate a key in a global 68 | // variable then use that key as the argument to context.WithValue and 69 | // Context.Value. A key can be any type that supports equality; 70 | // packages should define keys as an unexported type to avoid 71 | // collisions. 72 | // 73 | // Packages that define a Context key should provide type-safe accessors 74 | // for the values stores using that key: 75 | // 76 | // // Package user defines a User type that's stored in Contexts. 77 | // package user 78 | // 79 | // import "golang.org/x/net/context" 80 | // 81 | // // User is the type of value stored in the Contexts. 82 | // type User struct {...} 83 | // 84 | // // key is an unexported type for keys defined in this package. 85 | // // This prevents collisions with keys defined in other packages. 86 | // type key int 87 | // 88 | // // userKey is the key for user.User values in Contexts. It is 89 | // // unexported; clients use user.NewContext and user.FromContext 90 | // // instead of using this key directly. 91 | // var userKey key = 0 92 | // 93 | // // NewContext returns a new Context that carries value u. 94 | // func NewContext(ctx context.Context, u *User) context.Context { 95 | // return context.WithValue(ctx, userKey, u) 96 | // } 97 | // 98 | // // FromContext returns the User value stored in ctx, if any. 99 | // func FromContext(ctx context.Context) (*User, bool) { 100 | // u, ok := ctx.Value(userKey).(*User) 101 | // return u, ok 102 | // } 103 | Value(key interface{}) interface{} 104 | } 105 | 106 | // A CancelFunc tells an operation to abandon its work. 107 | // A CancelFunc does not wait for the work to stop. 108 | // After the first call, subsequent calls to a CancelFunc do nothing. 109 | type CancelFunc func() 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/pipe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "sync" 11 | ) 12 | 13 | // pipe is a goroutine-safe io.Reader/io.Writer pair. It's like 14 | // io.Pipe except there are no PipeReader/PipeWriter halves, and the 15 | // underlying buffer is an interface. (io.Pipe is always unbuffered) 16 | type pipe struct { 17 | mu sync.Mutex 18 | c sync.Cond // c.L lazily initialized to &p.mu 19 | b pipeBuffer // nil when done reading 20 | err error // read error once empty. non-nil means closed. 21 | breakErr error // immediate read error (caller doesn't see rest of b) 22 | donec chan struct{} // closed on error 23 | readFn func() // optional code to run in Read before error 24 | } 25 | 26 | type pipeBuffer interface { 27 | Len() int 28 | io.Writer 29 | io.Reader 30 | } 31 | 32 | func (p *pipe) Len() int { 33 | p.mu.Lock() 34 | defer p.mu.Unlock() 35 | if p.b == nil { 36 | return 0 37 | } 38 | return p.b.Len() 39 | } 40 | 41 | // Read waits until data is available and copies bytes 42 | // from the buffer into p. 43 | func (p *pipe) Read(d []byte) (n int, err error) { 44 | p.mu.Lock() 45 | defer p.mu.Unlock() 46 | if p.c.L == nil { 47 | p.c.L = &p.mu 48 | } 49 | for { 50 | if p.breakErr != nil { 51 | return 0, p.breakErr 52 | } 53 | if p.b != nil && p.b.Len() > 0 { 54 | return p.b.Read(d) 55 | } 56 | if p.err != nil { 57 | if p.readFn != nil { 58 | p.readFn() // e.g. copy trailers 59 | p.readFn = nil // not sticky like p.err 60 | } 61 | p.b = nil 62 | return 0, p.err 63 | } 64 | p.c.Wait() 65 | } 66 | } 67 | 68 | var errClosedPipeWrite = errors.New("write on closed buffer") 69 | 70 | // Write copies bytes from p into the buffer and wakes a reader. 71 | // It is an error to write more data than the buffer can hold. 72 | func (p *pipe) Write(d []byte) (n int, err error) { 73 | p.mu.Lock() 74 | defer p.mu.Unlock() 75 | if p.c.L == nil { 76 | p.c.L = &p.mu 77 | } 78 | defer p.c.Signal() 79 | if p.err != nil { 80 | return 0, errClosedPipeWrite 81 | } 82 | if p.breakErr != nil { 83 | return len(d), nil // discard when there is no reader 84 | } 85 | return p.b.Write(d) 86 | } 87 | 88 | // CloseWithError causes the next Read (waking up a current blocked 89 | // Read if needed) to return the provided err after all data has been 90 | // read. 91 | // 92 | // The error must be non-nil. 93 | func (p *pipe) CloseWithError(err error) { p.closeWithError(&p.err, err, nil) } 94 | 95 | // BreakWithError causes the next Read (waking up a current blocked 96 | // Read if needed) to return the provided err immediately, without 97 | // waiting for unread data. 98 | func (p *pipe) BreakWithError(err error) { p.closeWithError(&p.breakErr, err, nil) } 99 | 100 | // closeWithErrorAndCode is like CloseWithError but also sets some code to run 101 | // in the caller's goroutine before returning the error. 102 | func (p *pipe) closeWithErrorAndCode(err error, fn func()) { p.closeWithError(&p.err, err, fn) } 103 | 104 | func (p *pipe) closeWithError(dst *error, err error, fn func()) { 105 | if err == nil { 106 | panic("err must be non-nil") 107 | } 108 | p.mu.Lock() 109 | defer p.mu.Unlock() 110 | if p.c.L == nil { 111 | p.c.L = &p.mu 112 | } 113 | defer p.c.Signal() 114 | if *dst != nil { 115 | // Already been done. 116 | return 117 | } 118 | p.readFn = fn 119 | if dst == &p.breakErr { 120 | p.b = nil 121 | } 122 | *dst = err 123 | p.closeDoneLocked() 124 | } 125 | 126 | // requires p.mu be held. 127 | func (p *pipe) closeDoneLocked() { 128 | if p.donec == nil { 129 | return 130 | } 131 | // Close if unclosed. This isn't racy since we always 132 | // hold p.mu while closing. 133 | select { 134 | case <-p.donec: 135 | default: 136 | close(p.donec) 137 | } 138 | } 139 | 140 | // Err returns the error (if any) first set by BreakWithError or CloseWithError. 141 | func (p *pipe) Err() error { 142 | p.mu.Lock() 143 | defer p.mu.Unlock() 144 | if p.breakErr != nil { 145 | return p.breakErr 146 | } 147 | return p.err 148 | } 149 | 150 | // Done returns a channel which is closed if and when this pipe is closed 151 | // with CloseWithError. 152 | func (p *pipe) Done() <-chan struct{} { 153 | p.mu.Lock() 154 | defer p.mu.Unlock() 155 | if p.donec == nil { 156 | p.donec = make(chan struct{}) 157 | if p.err != nil || p.breakErr != nil { 158 | // Already hit an error. 159 | p.closeDoneLocked() 160 | } 161 | } 162 | return p.donec 163 | } 164 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/databuffer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | "sync" 11 | ) 12 | 13 | // Buffer chunks are allocated from a pool to reduce pressure on GC. 14 | // The maximum wasted space per dataBuffer is 2x the largest size class, 15 | // which happens when the dataBuffer has multiple chunks and there is 16 | // one unread byte in both the first and last chunks. We use a few size 17 | // classes to minimize overheads for servers that typically receive very 18 | // small request bodies. 19 | // 20 | // TODO: Benchmark to determine if the pools are necessary. The GC may have 21 | // improved enough that we can instead allocate chunks like this: 22 | // make([]byte, max(16<<10, expectedBytesRemaining)) 23 | var ( 24 | dataChunkSizeClasses = []int{ 25 | 1 << 10, 26 | 2 << 10, 27 | 4 << 10, 28 | 8 << 10, 29 | 16 << 10, 30 | } 31 | dataChunkPools = [...]sync.Pool{ 32 | {New: func() interface{} { return make([]byte, 1<<10) }}, 33 | {New: func() interface{} { return make([]byte, 2<<10) }}, 34 | {New: func() interface{} { return make([]byte, 4<<10) }}, 35 | {New: func() interface{} { return make([]byte, 8<<10) }}, 36 | {New: func() interface{} { return make([]byte, 16<<10) }}, 37 | } 38 | ) 39 | 40 | func getDataBufferChunk(size int64) []byte { 41 | i := 0 42 | for ; i < len(dataChunkSizeClasses)-1; i++ { 43 | if size <= int64(dataChunkSizeClasses[i]) { 44 | break 45 | } 46 | } 47 | return dataChunkPools[i].Get().([]byte) 48 | } 49 | 50 | func putDataBufferChunk(p []byte) { 51 | for i, n := range dataChunkSizeClasses { 52 | if len(p) == n { 53 | dataChunkPools[i].Put(p) 54 | return 55 | } 56 | } 57 | panic(fmt.Sprintf("unexpected buffer len=%v", len(p))) 58 | } 59 | 60 | // dataBuffer is an io.ReadWriter backed by a list of data chunks. 61 | // Each dataBuffer is used to read DATA frames on a single stream. 62 | // The buffer is divided into chunks so the server can limit the 63 | // total memory used by a single connection without limiting the 64 | // request body size on any single stream. 65 | type dataBuffer struct { 66 | chunks [][]byte 67 | r int // next byte to read is chunks[0][r] 68 | w int // next byte to write is chunks[len(chunks)-1][w] 69 | size int // total buffered bytes 70 | expected int64 // we expect at least this many bytes in future Write calls (ignored if <= 0) 71 | } 72 | 73 | var errReadEmpty = errors.New("read from empty dataBuffer") 74 | 75 | // Read copies bytes from the buffer into p. 76 | // It is an error to read when no data is available. 77 | func (b *dataBuffer) Read(p []byte) (int, error) { 78 | if b.size == 0 { 79 | return 0, errReadEmpty 80 | } 81 | var ntotal int 82 | for len(p) > 0 && b.size > 0 { 83 | readFrom := b.bytesFromFirstChunk() 84 | n := copy(p, readFrom) 85 | p = p[n:] 86 | ntotal += n 87 | b.r += n 88 | b.size -= n 89 | // If the first chunk has been consumed, advance to the next chunk. 90 | if b.r == len(b.chunks[0]) { 91 | putDataBufferChunk(b.chunks[0]) 92 | end := len(b.chunks) - 1 93 | copy(b.chunks[:end], b.chunks[1:]) 94 | b.chunks[end] = nil 95 | b.chunks = b.chunks[:end] 96 | b.r = 0 97 | } 98 | } 99 | return ntotal, nil 100 | } 101 | 102 | func (b *dataBuffer) bytesFromFirstChunk() []byte { 103 | if len(b.chunks) == 1 { 104 | return b.chunks[0][b.r:b.w] 105 | } 106 | return b.chunks[0][b.r:] 107 | } 108 | 109 | // Len returns the number of bytes of the unread portion of the buffer. 110 | func (b *dataBuffer) Len() int { 111 | return b.size 112 | } 113 | 114 | // Write appends p to the buffer. 115 | func (b *dataBuffer) Write(p []byte) (int, error) { 116 | ntotal := len(p) 117 | for len(p) > 0 { 118 | // If the last chunk is empty, allocate a new chunk. Try to allocate 119 | // enough to fully copy p plus any additional bytes we expect to 120 | // receive. However, this may allocate less than len(p). 121 | want := int64(len(p)) 122 | if b.expected > want { 123 | want = b.expected 124 | } 125 | chunk := b.lastChunkOrAlloc(want) 126 | n := copy(chunk[b.w:], p) 127 | p = p[n:] 128 | b.w += n 129 | b.size += n 130 | b.expected -= int64(n) 131 | } 132 | return ntotal, nil 133 | } 134 | 135 | func (b *dataBuffer) lastChunkOrAlloc(want int64) []byte { 136 | if len(b.chunks) != 0 { 137 | last := b.chunks[len(b.chunks)-1] 138 | if b.w < len(last) { 139 | return last 140 | } 141 | } 142 | chunk := getDataBufferChunk(want) 143 | b.chunks = append(b.chunks, chunk) 144 | b.w = 0 145 | return chunk 146 | } 147 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/metadata/metadata.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package metadata define the structure of the metadata supported by gRPC library. 20 | // Please refer to https://grpc.io/docs/guides/wire.html for more information about custom-metadata. 21 | package metadata // import "google.golang.org/grpc/metadata" 22 | 23 | import ( 24 | "fmt" 25 | "strings" 26 | 27 | "golang.org/x/net/context" 28 | ) 29 | 30 | // DecodeKeyValue returns k, v, nil. It is deprecated and should not be used. 31 | func DecodeKeyValue(k, v string) (string, string, error) { 32 | return k, v, nil 33 | } 34 | 35 | // MD is a mapping from metadata keys to values. Users should use the following 36 | // two convenience functions New and Pairs to generate MD. 37 | type MD map[string][]string 38 | 39 | // New creates an MD from a given key-value map. 40 | // 41 | // Only the following ASCII characters are allowed in keys: 42 | // - digits: 0-9 43 | // - uppercase letters: A-Z (normalized to lower) 44 | // - lowercase letters: a-z 45 | // - special characters: -_. 46 | // Uppercase letters are automatically converted to lowercase. 47 | // 48 | // Keys beginning with "grpc-" are reserved for grpc-internal use only and may 49 | // result in errors if set in metadata. 50 | func New(m map[string]string) MD { 51 | md := MD{} 52 | for k, val := range m { 53 | key := strings.ToLower(k) 54 | md[key] = append(md[key], val) 55 | } 56 | return md 57 | } 58 | 59 | // Pairs returns an MD formed by the mapping of key, value ... 60 | // Pairs panics if len(kv) is odd. 61 | // 62 | // Only the following ASCII characters are allowed in keys: 63 | // - digits: 0-9 64 | // - uppercase letters: A-Z (normalized to lower) 65 | // - lowercase letters: a-z 66 | // - special characters: -_. 67 | // Uppercase letters are automatically converted to lowercase. 68 | // 69 | // Keys beginning with "grpc-" are reserved for grpc-internal use only and may 70 | // result in errors if set in metadata. 71 | func Pairs(kv ...string) MD { 72 | if len(kv)%2 == 1 { 73 | panic(fmt.Sprintf("metadata: Pairs got the odd number of input pairs for metadata: %d", len(kv))) 74 | } 75 | md := MD{} 76 | var key string 77 | for i, s := range kv { 78 | if i%2 == 0 { 79 | key = strings.ToLower(s) 80 | continue 81 | } 82 | md[key] = append(md[key], s) 83 | } 84 | return md 85 | } 86 | 87 | // Len returns the number of items in md. 88 | func (md MD) Len() int { 89 | return len(md) 90 | } 91 | 92 | // Copy returns a copy of md. 93 | func (md MD) Copy() MD { 94 | return Join(md) 95 | } 96 | 97 | // Join joins any number of mds into a single MD. 98 | // The order of values for each key is determined by the order in which 99 | // the mds containing those values are presented to Join. 100 | func Join(mds ...MD) MD { 101 | out := MD{} 102 | for _, md := range mds { 103 | for k, v := range md { 104 | out[k] = append(out[k], v...) 105 | } 106 | } 107 | return out 108 | } 109 | 110 | type mdIncomingKey struct{} 111 | type mdOutgoingKey struct{} 112 | 113 | // NewIncomingContext creates a new context with incoming md attached. 114 | func NewIncomingContext(ctx context.Context, md MD) context.Context { 115 | return context.WithValue(ctx, mdIncomingKey{}, md) 116 | } 117 | 118 | // NewOutgoingContext creates a new context with outgoing md attached. 119 | func NewOutgoingContext(ctx context.Context, md MD) context.Context { 120 | return context.WithValue(ctx, mdOutgoingKey{}, md) 121 | } 122 | 123 | // FromIncomingContext returns the incoming metadata in ctx if it exists. The 124 | // returned MD should not be modified. Writing to it may cause races. 125 | // Modification should be made to copies of the returned MD. 126 | func FromIncomingContext(ctx context.Context) (md MD, ok bool) { 127 | md, ok = ctx.Value(mdIncomingKey{}).(MD) 128 | return 129 | } 130 | 131 | // FromOutgoingContext returns the outgoing metadata in ctx if it exists. The 132 | // returned MD should not be modified. Writing to it may cause races. 133 | // Modification should be made to the copies of the returned MD. 134 | func FromOutgoingContext(ctx context.Context) (md MD, ok bool) { 135 | md, ok = ctx.Value(mdOutgoingKey{}).(MD) 136 | return 137 | } 138 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | ) 11 | 12 | // An ErrCode is an unsigned 32-bit error code as defined in the HTTP/2 spec. 13 | type ErrCode uint32 14 | 15 | const ( 16 | ErrCodeNo ErrCode = 0x0 17 | ErrCodeProtocol ErrCode = 0x1 18 | ErrCodeInternal ErrCode = 0x2 19 | ErrCodeFlowControl ErrCode = 0x3 20 | ErrCodeSettingsTimeout ErrCode = 0x4 21 | ErrCodeStreamClosed ErrCode = 0x5 22 | ErrCodeFrameSize ErrCode = 0x6 23 | ErrCodeRefusedStream ErrCode = 0x7 24 | ErrCodeCancel ErrCode = 0x8 25 | ErrCodeCompression ErrCode = 0x9 26 | ErrCodeConnect ErrCode = 0xa 27 | ErrCodeEnhanceYourCalm ErrCode = 0xb 28 | ErrCodeInadequateSecurity ErrCode = 0xc 29 | ErrCodeHTTP11Required ErrCode = 0xd 30 | ) 31 | 32 | var errCodeName = map[ErrCode]string{ 33 | ErrCodeNo: "NO_ERROR", 34 | ErrCodeProtocol: "PROTOCOL_ERROR", 35 | ErrCodeInternal: "INTERNAL_ERROR", 36 | ErrCodeFlowControl: "FLOW_CONTROL_ERROR", 37 | ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT", 38 | ErrCodeStreamClosed: "STREAM_CLOSED", 39 | ErrCodeFrameSize: "FRAME_SIZE_ERROR", 40 | ErrCodeRefusedStream: "REFUSED_STREAM", 41 | ErrCodeCancel: "CANCEL", 42 | ErrCodeCompression: "COMPRESSION_ERROR", 43 | ErrCodeConnect: "CONNECT_ERROR", 44 | ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM", 45 | ErrCodeInadequateSecurity: "INADEQUATE_SECURITY", 46 | ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED", 47 | } 48 | 49 | func (e ErrCode) String() string { 50 | if s, ok := errCodeName[e]; ok { 51 | return s 52 | } 53 | return fmt.Sprintf("unknown error code 0x%x", uint32(e)) 54 | } 55 | 56 | // ConnectionError is an error that results in the termination of the 57 | // entire connection. 58 | type ConnectionError ErrCode 59 | 60 | func (e ConnectionError) Error() string { return fmt.Sprintf("connection error: %s", ErrCode(e)) } 61 | 62 | // StreamError is an error that only affects one stream within an 63 | // HTTP/2 connection. 64 | type StreamError struct { 65 | StreamID uint32 66 | Code ErrCode 67 | Cause error // optional additional detail 68 | } 69 | 70 | func streamError(id uint32, code ErrCode) StreamError { 71 | return StreamError{StreamID: id, Code: code} 72 | } 73 | 74 | func (e StreamError) Error() string { 75 | if e.Cause != nil { 76 | return fmt.Sprintf("stream error: stream ID %d; %v; %v", e.StreamID, e.Code, e.Cause) 77 | } 78 | return fmt.Sprintf("stream error: stream ID %d; %v", e.StreamID, e.Code) 79 | } 80 | 81 | // 6.9.1 The Flow Control Window 82 | // "If a sender receives a WINDOW_UPDATE that causes a flow control 83 | // window to exceed this maximum it MUST terminate either the stream 84 | // or the connection, as appropriate. For streams, [...]; for the 85 | // connection, a GOAWAY frame with a FLOW_CONTROL_ERROR code." 86 | type goAwayFlowError struct{} 87 | 88 | func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" } 89 | 90 | // connError represents an HTTP/2 ConnectionError error code, along 91 | // with a string (for debugging) explaining why. 92 | // 93 | // Errors of this type are only returned by the frame parser functions 94 | // and converted into ConnectionError(Code), after stashing away 95 | // the Reason into the Framer's errDetail field, accessible via 96 | // the (*Framer).ErrorDetail method. 97 | type connError struct { 98 | Code ErrCode // the ConnectionError error code 99 | Reason string // additional reason 100 | } 101 | 102 | func (e connError) Error() string { 103 | return fmt.Sprintf("http2: connection error: %v: %v", e.Code, e.Reason) 104 | } 105 | 106 | type pseudoHeaderError string 107 | 108 | func (e pseudoHeaderError) Error() string { 109 | return fmt.Sprintf("invalid pseudo-header %q", string(e)) 110 | } 111 | 112 | type duplicatePseudoHeaderError string 113 | 114 | func (e duplicatePseudoHeaderError) Error() string { 115 | return fmt.Sprintf("duplicate pseudo-header %q", string(e)) 116 | } 117 | 118 | type headerFieldNameError string 119 | 120 | func (e headerFieldNameError) Error() string { 121 | return fmt.Sprintf("invalid header field name %q", string(e)) 122 | } 123 | 124 | type headerFieldValueError string 125 | 126 | func (e headerFieldValueError) Error() string { 127 | return fmt.Sprintf("invalid header field value %q", string(e)) 128 | } 129 | 130 | var ( 131 | errMixPseudoHeaderTypes = errors.New("mix of request and response pseudo headers") 132 | errPseudoAfterRegular = errors.New("pseudo header field after regular") 133 | ) 134 | -------------------------------------------------------------------------------- /vendor/google.golang.org/grpc/transport/bdp_estimator.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package transport 20 | 21 | import ( 22 | "sync" 23 | "time" 24 | ) 25 | 26 | const ( 27 | // bdpLimit is the maximum value the flow control windows 28 | // will be increased to. 29 | bdpLimit = (1 << 20) * 4 30 | // alpha is a constant factor used to keep a moving average 31 | // of RTTs. 32 | alpha = 0.9 33 | // If the current bdp sample is greater than or equal to 34 | // our beta * our estimated bdp and the current bandwidth 35 | // sample is the maximum bandwidth observed so far, we 36 | // increase our bbp estimate by a factor of gamma. 37 | beta = 0.66 38 | // To put our bdp to be smaller than or equal to twice the real BDP, 39 | // we should multiply our current sample with 4/3, however to round things out 40 | // we use 2 as the multiplication factor. 41 | gamma = 2 42 | ) 43 | 44 | var ( 45 | // Adding arbitrary data to ping so that its ack can be 46 | // identified. 47 | // Easter-egg: what does the ping message say? 48 | bdpPing = &ping{data: [8]byte{2, 4, 16, 16, 9, 14, 7, 7}} 49 | ) 50 | 51 | type bdpEstimator struct { 52 | // sentAt is the time when the ping was sent. 53 | sentAt time.Time 54 | 55 | mu sync.Mutex 56 | // bdp is the current bdp estimate. 57 | bdp uint32 58 | // sample is the number of bytes received in one measurement cycle. 59 | sample uint32 60 | // bwMax is the maximum bandwidth noted so far (bytes/sec). 61 | bwMax float64 62 | // bool to keep track of the begining of a new measurement cycle. 63 | isSent bool 64 | // Callback to update the window sizes. 65 | updateFlowControl func(n uint32) 66 | // sampleCount is the number of samples taken so far. 67 | sampleCount uint64 68 | // round trip time (seconds) 69 | rtt float64 70 | } 71 | 72 | // timesnap registers the time bdp ping was sent out so that 73 | // network rtt can be calculated when its ack is recieved. 74 | // It is called (by controller) when the bdpPing is 75 | // being written on the wire. 76 | func (b *bdpEstimator) timesnap(d [8]byte) { 77 | if bdpPing.data != d { 78 | return 79 | } 80 | b.sentAt = time.Now() 81 | } 82 | 83 | // add adds bytes to the current sample for calculating bdp. 84 | // It returns true only if a ping must be sent. This can be used 85 | // by the caller (handleData) to make decision about batching 86 | // a window update with it. 87 | func (b *bdpEstimator) add(n uint32) bool { 88 | b.mu.Lock() 89 | defer b.mu.Unlock() 90 | if b.bdp == bdpLimit { 91 | return false 92 | } 93 | if !b.isSent { 94 | b.isSent = true 95 | b.sample = n 96 | b.sentAt = time.Time{} 97 | b.sampleCount++ 98 | return true 99 | } 100 | b.sample += n 101 | return false 102 | } 103 | 104 | // calculate is called when an ack for a bdp ping is received. 105 | // Here we calculate the current bdp and bandwidth sample and 106 | // decide if the flow control windows should go up. 107 | func (b *bdpEstimator) calculate(d [8]byte) { 108 | // Check if the ping acked for was the bdp ping. 109 | if bdpPing.data != d { 110 | return 111 | } 112 | b.mu.Lock() 113 | rttSample := time.Since(b.sentAt).Seconds() 114 | if b.sampleCount < 10 { 115 | // Bootstrap rtt with an average of first 10 rtt samples. 116 | b.rtt += (rttSample - b.rtt) / float64(b.sampleCount) 117 | } else { 118 | // Heed to the recent past more. 119 | b.rtt += (rttSample - b.rtt) * float64(alpha) 120 | } 121 | b.isSent = false 122 | // The number of bytes accumalated so far in the sample is smaller 123 | // than or equal to 1.5 times the real BDP on a saturated connection. 124 | bwCurrent := float64(b.sample) / (b.rtt * float64(1.5)) 125 | if bwCurrent > b.bwMax { 126 | b.bwMax = bwCurrent 127 | } 128 | // If the current sample (which is smaller than or equal to the 1.5 times the real BDP) is 129 | // greater than or equal to 2/3rd our perceived bdp AND this is the maximum bandwidth seen so far, we 130 | // should update our perception of the network BDP. 131 | if float64(b.sample) >= beta*float64(b.bdp) && bwCurrent == b.bwMax && b.bdp != bdpLimit { 132 | sampleFloat := float64(b.sample) 133 | b.bdp = uint32(gamma * sampleFloat) 134 | if b.bdp > bdpLimit { 135 | b.bdp = bdpLimit 136 | } 137 | bdp := b.bdp 138 | b.mu.Unlock() 139 | b.updateFlowControl(bdp) 140 | return 141 | } 142 | b.mu.Unlock() 143 | } 144 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/timestamp"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "TimestampProto"; 40 | option java_multiple_files = true; 41 | option java_generate_equals_and_hash = true; 42 | option objc_class_prefix = "GPB"; 43 | 44 | // A Timestamp represents a point in time independent of any time zone 45 | // or calendar, represented as seconds and fractions of seconds at 46 | // nanosecond resolution in UTC Epoch time. It is encoded using the 47 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 48 | // backwards to year one. It is encoded assuming all minutes are 60 49 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 50 | // table is needed for interpretation. Range is from 51 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 52 | // By restricting to that range, we ensure that we can convert to 53 | // and from RFC 3339 date strings. 54 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 55 | // 56 | // Example 1: Compute Timestamp from POSIX `time()`. 57 | // 58 | // Timestamp timestamp; 59 | // timestamp.set_seconds(time(NULL)); 60 | // timestamp.set_nanos(0); 61 | // 62 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 63 | // 64 | // struct timeval tv; 65 | // gettimeofday(&tv, NULL); 66 | // 67 | // Timestamp timestamp; 68 | // timestamp.set_seconds(tv.tv_sec); 69 | // timestamp.set_nanos(tv.tv_usec * 1000); 70 | // 71 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 72 | // 73 | // FILETIME ft; 74 | // GetSystemTimeAsFileTime(&ft); 75 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 76 | // 77 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 78 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 79 | // Timestamp timestamp; 80 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 81 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 82 | // 83 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 84 | // 85 | // long millis = System.currentTimeMillis(); 86 | // 87 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 88 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 89 | // 90 | // 91 | // Example 5: Compute Timestamp from current time in Python. 92 | // 93 | // now = time.time() 94 | // seconds = int(now) 95 | // nanos = int((now - seconds) * 10**9) 96 | // timestamp = Timestamp(seconds=seconds, nanos=nanos) 97 | // 98 | // 99 | message Timestamp { 100 | 101 | // Represents seconds of UTC time since Unix epoch 102 | // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to 103 | // 9999-12-31T23:59:59Z inclusive. 104 | int64 seconds = 1; 105 | 106 | // Non-negative fractions of a second at nanosecond resolution. Negative 107 | // second values with fractions must still have non-negative nanos values 108 | // that count forward in time. Must be from 0 to 999,999,999 109 | // inclusive. 110 | int32 nanos = 2; 111 | } 112 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/timestamp.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package ptypes 33 | 34 | // This file implements operations on google.protobuf.Timestamp. 35 | 36 | import ( 37 | "errors" 38 | "fmt" 39 | "time" 40 | 41 | tspb "github.com/golang/protobuf/ptypes/timestamp" 42 | ) 43 | 44 | const ( 45 | // Seconds field of the earliest valid Timestamp. 46 | // This is time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). 47 | minValidSeconds = -62135596800 48 | // Seconds field just after the latest valid Timestamp. 49 | // This is time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). 50 | maxValidSeconds = 253402300800 51 | ) 52 | 53 | // validateTimestamp determines whether a Timestamp is valid. 54 | // A valid timestamp represents a time in the range 55 | // [0001-01-01, 10000-01-01) and has a Nanos field 56 | // in the range [0, 1e9). 57 | // 58 | // If the Timestamp is valid, validateTimestamp returns nil. 59 | // Otherwise, it returns an error that describes 60 | // the problem. 61 | // 62 | // Every valid Timestamp can be represented by a time.Time, but the converse is not true. 63 | func validateTimestamp(ts *tspb.Timestamp) error { 64 | if ts == nil { 65 | return errors.New("timestamp: nil Timestamp") 66 | } 67 | if ts.Seconds < minValidSeconds { 68 | return fmt.Errorf("timestamp: %v before 0001-01-01", ts) 69 | } 70 | if ts.Seconds >= maxValidSeconds { 71 | return fmt.Errorf("timestamp: %v after 10000-01-01", ts) 72 | } 73 | if ts.Nanos < 0 || ts.Nanos >= 1e9 { 74 | return fmt.Errorf("timestamp: %v: nanos not in range [0, 1e9)", ts) 75 | } 76 | return nil 77 | } 78 | 79 | // Timestamp converts a google.protobuf.Timestamp proto to a time.Time. 80 | // It returns an error if the argument is invalid. 81 | // 82 | // Unlike most Go functions, if Timestamp returns an error, the first return value 83 | // is not the zero time.Time. Instead, it is the value obtained from the 84 | // time.Unix function when passed the contents of the Timestamp, in the UTC 85 | // locale. This may or may not be a meaningful time; many invalid Timestamps 86 | // do map to valid time.Times. 87 | // 88 | // A nil Timestamp returns an error. The first return value in that case is 89 | // undefined. 90 | func Timestamp(ts *tspb.Timestamp) (time.Time, error) { 91 | // Don't return the zero value on error, because corresponds to a valid 92 | // timestamp. Instead return whatever time.Unix gives us. 93 | var t time.Time 94 | if ts == nil { 95 | t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp 96 | } else { 97 | t = time.Unix(ts.Seconds, int64(ts.Nanos)).UTC() 98 | } 99 | return t, validateTimestamp(ts) 100 | } 101 | 102 | // TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. 103 | // It returns an error if the resulting Timestamp is invalid. 104 | func TimestampProto(t time.Time) (*tspb.Timestamp, error) { 105 | seconds := t.Unix() 106 | nanos := int32(t.Sub(time.Unix(seconds, 0))) 107 | ts := &tspb.Timestamp{ 108 | Seconds: seconds, 109 | Nanos: nanos, 110 | } 111 | if err := validateTimestamp(ts); err != nil { 112 | return nil, err 113 | } 114 | return ts, nil 115 | } 116 | 117 | // TimestampString returns the RFC 3339 string for valid Timestamps. For invalid 118 | // Timestamps, it returns an error message in parentheses. 119 | func TimestampString(ts *tspb.Timestamp) string { 120 | t, err := Timestamp(ts) 121 | if err != nil { 122 | return fmt.Sprintf("(%v)", err) 123 | } 124 | return t.Format(time.RFC3339Nano) 125 | } 126 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/duration/duration.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: github.com/golang/protobuf/ptypes/duration/duration.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package duration is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | github.com/golang/protobuf/ptypes/duration/duration.proto 10 | 11 | It has these top-level messages: 12 | Duration 13 | */ 14 | package duration 15 | 16 | import proto "github.com/golang/protobuf/proto" 17 | import fmt "fmt" 18 | import math "math" 19 | 20 | // Reference imports to suppress errors if they are not otherwise used. 21 | var _ = proto.Marshal 22 | var _ = fmt.Errorf 23 | var _ = math.Inf 24 | 25 | // This is a compile-time assertion to ensure that this generated file 26 | // is compatible with the proto package it is being compiled against. 27 | // A compilation error at this line likely means your copy of the 28 | // proto package needs to be updated. 29 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 30 | 31 | // A Duration represents a signed, fixed-length span of time represented 32 | // as a count of seconds and fractions of seconds at nanosecond 33 | // resolution. It is independent of any calendar and concepts like "day" 34 | // or "month". It is related to Timestamp in that the difference between 35 | // two Timestamp values is a Duration and it can be added or subtracted 36 | // from a Timestamp. Range is approximately +-10,000 years. 37 | // 38 | // Example 1: Compute Duration from two Timestamps in pseudo code. 39 | // 40 | // Timestamp start = ...; 41 | // Timestamp end = ...; 42 | // Duration duration = ...; 43 | // 44 | // duration.seconds = end.seconds - start.seconds; 45 | // duration.nanos = end.nanos - start.nanos; 46 | // 47 | // if (duration.seconds < 0 && duration.nanos > 0) { 48 | // duration.seconds += 1; 49 | // duration.nanos -= 1000000000; 50 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 51 | // duration.seconds -= 1; 52 | // duration.nanos += 1000000000; 53 | // } 54 | // 55 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 56 | // 57 | // Timestamp start = ...; 58 | // Duration duration = ...; 59 | // Timestamp end = ...; 60 | // 61 | // end.seconds = start.seconds + duration.seconds; 62 | // end.nanos = start.nanos + duration.nanos; 63 | // 64 | // if (end.nanos < 0) { 65 | // end.seconds -= 1; 66 | // end.nanos += 1000000000; 67 | // } else if (end.nanos >= 1000000000) { 68 | // end.seconds += 1; 69 | // end.nanos -= 1000000000; 70 | // } 71 | // 72 | // 73 | type Duration struct { 74 | // Signed seconds of the span of time. Must be from -315,576,000,000 75 | // to +315,576,000,000 inclusive. 76 | Seconds int64 `protobuf:"varint,1,opt,name=seconds" json:"seconds,omitempty"` 77 | // Signed fractions of a second at nanosecond resolution of the span 78 | // of time. Durations less than one second are represented with a 0 79 | // `seconds` field and a positive or negative `nanos` field. For durations 80 | // of one second or more, a non-zero value for the `nanos` field must be 81 | // of the same sign as the `seconds` field. Must be from -999,999,999 82 | // to +999,999,999 inclusive. 83 | Nanos int32 `protobuf:"varint,2,opt,name=nanos" json:"nanos,omitempty"` 84 | } 85 | 86 | func (m *Duration) Reset() { *m = Duration{} } 87 | func (m *Duration) String() string { return proto.CompactTextString(m) } 88 | func (*Duration) ProtoMessage() {} 89 | func (*Duration) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 90 | func (*Duration) XXX_WellKnownType() string { return "Duration" } 91 | 92 | func init() { 93 | proto.RegisterType((*Duration)(nil), "google.protobuf.Duration") 94 | } 95 | 96 | func init() { 97 | proto.RegisterFile("github.com/golang/protobuf/ptypes/duration/duration.proto", fileDescriptor0) 98 | } 99 | 100 | var fileDescriptor0 = []byte{ 101 | // 189 bytes of a gzipped FileDescriptorProto 102 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xb2, 0x4c, 0xcf, 0x2c, 0xc9, 103 | 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0xcf, 0x49, 0xcc, 0x4b, 0xd7, 0x2f, 0x28, 104 | 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x2f, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x4f, 0x29, 105 | 0x2d, 0x4a, 0x2c, 0xc9, 0xcc, 0xcf, 0x83, 0x33, 0xf4, 0xc0, 0x2a, 0x84, 0xf8, 0xd3, 0xf3, 0xf3, 106 | 0xd3, 0x73, 0x52, 0xf5, 0x60, 0xea, 0x95, 0xac, 0xb8, 0x38, 0x5c, 0xa0, 0x4a, 0x84, 0x24, 0xb8, 107 | 0xd8, 0x8b, 0x53, 0x93, 0xf3, 0xf3, 0x52, 0x8a, 0x25, 0x18, 0x15, 0x18, 0x35, 0x98, 0x83, 0x60, 108 | 0x5c, 0x21, 0x11, 0x2e, 0xd6, 0xbc, 0xc4, 0xbc, 0xfc, 0x62, 0x09, 0x26, 0x05, 0x46, 0x0d, 0xd6, 109 | 0x20, 0x08, 0xc7, 0xa9, 0x86, 0x4b, 0x38, 0x39, 0x3f, 0x57, 0x0f, 0xcd, 0x48, 0x27, 0x5e, 0x98, 110 | 0x81, 0x01, 0x20, 0x91, 0x00, 0xc6, 0x28, 0x2d, 0xe2, 0xdd, 0xbb, 0x80, 0x91, 0x71, 0x11, 0x13, 111 | 0xb3, 0x7b, 0x80, 0xd3, 0x2a, 0x26, 0x39, 0x77, 0x88, 0xb9, 0x01, 0x50, 0xa5, 0x7a, 0xe1, 0xa9, 112 | 0x39, 0x39, 0xde, 0x79, 0xf9, 0xe5, 0x79, 0x21, 0x20, 0x2d, 0x49, 0x6c, 0x60, 0x33, 0x8c, 0x01, 113 | 0x01, 0x00, 0x00, 0xff, 0xff, 0x62, 0xfb, 0xb1, 0x51, 0x0e, 0x01, 0x00, 0x00, 114 | } 115 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/ptypes/any.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package ptypes 33 | 34 | // This file implements functions to marshal proto.Message to/from 35 | // google.protobuf.Any message. 36 | 37 | import ( 38 | "fmt" 39 | "reflect" 40 | "strings" 41 | 42 | "github.com/golang/protobuf/proto" 43 | "github.com/golang/protobuf/ptypes/any" 44 | ) 45 | 46 | const googleApis = "type.googleapis.com/" 47 | 48 | // AnyMessageName returns the name of the message contained in a google.protobuf.Any message. 49 | // 50 | // Note that regular type assertions should be done using the Is 51 | // function. AnyMessageName is provided for less common use cases like filtering a 52 | // sequence of Any messages based on a set of allowed message type names. 53 | func AnyMessageName(any *any.Any) (string, error) { 54 | slash := strings.LastIndex(any.TypeUrl, "/") 55 | if slash < 0 { 56 | return "", fmt.Errorf("message type url %q is invalid", any.TypeUrl) 57 | } 58 | return any.TypeUrl[slash+1:], nil 59 | } 60 | 61 | // MarshalAny takes the protocol buffer and encodes it into google.protobuf.Any. 62 | func MarshalAny(pb proto.Message) (*any.Any, error) { 63 | value, err := proto.Marshal(pb) 64 | if err != nil { 65 | return nil, err 66 | } 67 | return &any.Any{TypeUrl: googleApis + proto.MessageName(pb), Value: value}, nil 68 | } 69 | 70 | // DynamicAny is a value that can be passed to UnmarshalAny to automatically 71 | // allocate a proto.Message for the type specified in a google.protobuf.Any 72 | // message. The allocated message is stored in the embedded proto.Message. 73 | // 74 | // Example: 75 | // 76 | // var x ptypes.DynamicAny 77 | // if err := ptypes.UnmarshalAny(a, &x); err != nil { ... } 78 | // fmt.Printf("unmarshaled message: %v", x.Message) 79 | type DynamicAny struct { 80 | proto.Message 81 | } 82 | 83 | // Empty returns a new proto.Message of the type specified in a 84 | // google.protobuf.Any message. It returns an error if corresponding message 85 | // type isn't linked in. 86 | func Empty(any *any.Any) (proto.Message, error) { 87 | aname, err := AnyMessageName(any) 88 | if err != nil { 89 | return nil, err 90 | } 91 | 92 | t := proto.MessageType(aname) 93 | if t == nil { 94 | return nil, fmt.Errorf("any: message type %q isn't linked in", aname) 95 | } 96 | return reflect.New(t.Elem()).Interface().(proto.Message), nil 97 | } 98 | 99 | // UnmarshalAny parses the protocol buffer representation in a google.protobuf.Any 100 | // message and places the decoded result in pb. It returns an error if type of 101 | // contents of Any message does not match type of pb message. 102 | // 103 | // pb can be a proto.Message, or a *DynamicAny. 104 | func UnmarshalAny(any *any.Any, pb proto.Message) error { 105 | if d, ok := pb.(*DynamicAny); ok { 106 | if d.Message == nil { 107 | var err error 108 | d.Message, err = Empty(any) 109 | if err != nil { 110 | return err 111 | } 112 | } 113 | return UnmarshalAny(any, d.Message) 114 | } 115 | 116 | aname, err := AnyMessageName(any) 117 | if err != nil { 118 | return err 119 | } 120 | 121 | mname := proto.MessageName(pb) 122 | if aname != mname { 123 | return fmt.Errorf("mismatched message type: got %q want %q", aname, mname) 124 | } 125 | return proto.Unmarshal(any.Value, pb) 126 | } 127 | 128 | // Is returns true if any value contains a given message type. 129 | func Is(any *any.Any, pb proto.Message) bool { 130 | aname, err := AnyMessageName(any) 131 | if err != nil { 132 | return false 133 | } 134 | 135 | return aname == proto.MessageName(pb) 136 | } 137 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/punycode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package idna 6 | 7 | // This file implements the Punycode algorithm from RFC 3492. 8 | 9 | import ( 10 | "fmt" 11 | "math" 12 | "strings" 13 | "unicode/utf8" 14 | ) 15 | 16 | // These parameter values are specified in section 5. 17 | // 18 | // All computation is done with int32s, so that overflow behavior is identical 19 | // regardless of whether int is 32-bit or 64-bit. 20 | const ( 21 | base int32 = 36 22 | damp int32 = 700 23 | initialBias int32 = 72 24 | initialN int32 = 128 25 | skew int32 = 38 26 | tmax int32 = 26 27 | tmin int32 = 1 28 | ) 29 | 30 | // decode decodes a string as specified in section 6.2. 31 | func decode(encoded string) (string, error) { 32 | if encoded == "" { 33 | return "", nil 34 | } 35 | pos := 1 + strings.LastIndex(encoded, "-") 36 | if pos == 1 { 37 | return "", fmt.Errorf("idna: invalid label %q", encoded) 38 | } 39 | if pos == len(encoded) { 40 | return encoded[:len(encoded)-1], nil 41 | } 42 | output := make([]rune, 0, len(encoded)) 43 | if pos != 0 { 44 | for _, r := range encoded[:pos-1] { 45 | output = append(output, r) 46 | } 47 | } 48 | i, n, bias := int32(0), initialN, initialBias 49 | for pos < len(encoded) { 50 | oldI, w := i, int32(1) 51 | for k := base; ; k += base { 52 | if pos == len(encoded) { 53 | return "", fmt.Errorf("idna: invalid label %q", encoded) 54 | } 55 | digit, ok := decodeDigit(encoded[pos]) 56 | if !ok { 57 | return "", fmt.Errorf("idna: invalid label %q", encoded) 58 | } 59 | pos++ 60 | i += digit * w 61 | if i < 0 { 62 | return "", fmt.Errorf("idna: invalid label %q", encoded) 63 | } 64 | t := k - bias 65 | if t < tmin { 66 | t = tmin 67 | } else if t > tmax { 68 | t = tmax 69 | } 70 | if digit < t { 71 | break 72 | } 73 | w *= base - t 74 | if w >= math.MaxInt32/base { 75 | return "", fmt.Errorf("idna: invalid label %q", encoded) 76 | } 77 | } 78 | x := int32(len(output) + 1) 79 | bias = adapt(i-oldI, x, oldI == 0) 80 | n += i / x 81 | i %= x 82 | if n > utf8.MaxRune || len(output) >= 1024 { 83 | return "", fmt.Errorf("idna: invalid label %q", encoded) 84 | } 85 | output = append(output, 0) 86 | copy(output[i+1:], output[i:]) 87 | output[i] = n 88 | i++ 89 | } 90 | return string(output), nil 91 | } 92 | 93 | // encode encodes a string as specified in section 6.3 and prepends prefix to 94 | // the result. 95 | // 96 | // The "while h < length(input)" line in the specification becomes "for 97 | // remaining != 0" in the Go code, because len(s) in Go is in bytes, not runes. 98 | func encode(prefix, s string) (string, error) { 99 | output := make([]byte, len(prefix), len(prefix)+1+2*len(s)) 100 | copy(output, prefix) 101 | delta, n, bias := int32(0), initialN, initialBias 102 | b, remaining := int32(0), int32(0) 103 | for _, r := range s { 104 | if r < 0x80 { 105 | b++ 106 | output = append(output, byte(r)) 107 | } else { 108 | remaining++ 109 | } 110 | } 111 | h := b 112 | if b > 0 { 113 | output = append(output, '-') 114 | } 115 | for remaining != 0 { 116 | m := int32(0x7fffffff) 117 | for _, r := range s { 118 | if m > r && r >= n { 119 | m = r 120 | } 121 | } 122 | delta += (m - n) * (h + 1) 123 | if delta < 0 { 124 | return "", fmt.Errorf("idna: invalid label %q", s) 125 | } 126 | n = m 127 | for _, r := range s { 128 | if r < n { 129 | delta++ 130 | if delta < 0 { 131 | return "", fmt.Errorf("idna: invalid label %q", s) 132 | } 133 | continue 134 | } 135 | if r > n { 136 | continue 137 | } 138 | q := delta 139 | for k := base; ; k += base { 140 | t := k - bias 141 | if t < tmin { 142 | t = tmin 143 | } else if t > tmax { 144 | t = tmax 145 | } 146 | if q < t { 147 | break 148 | } 149 | output = append(output, encodeDigit(t+(q-t)%(base-t))) 150 | q = (q - t) / (base - t) 151 | } 152 | output = append(output, encodeDigit(q)) 153 | bias = adapt(delta, h+1, h == b) 154 | delta = 0 155 | h++ 156 | remaining-- 157 | } 158 | delta++ 159 | n++ 160 | } 161 | return string(output), nil 162 | } 163 | 164 | func decodeDigit(x byte) (digit int32, ok bool) { 165 | switch { 166 | case '0' <= x && x <= '9': 167 | return int32(x - ('0' - 26)), true 168 | case 'A' <= x && x <= 'Z': 169 | return int32(x - 'A'), true 170 | case 'a' <= x && x <= 'z': 171 | return int32(x - 'a'), true 172 | } 173 | return 0, false 174 | } 175 | 176 | func encodeDigit(digit int32) byte { 177 | switch { 178 | case 0 <= digit && digit < 26: 179 | return byte(digit + 'a') 180 | case 26 <= digit && digit < 36: 181 | return byte(digit + ('0' - 26)) 182 | } 183 | panic("idna: internal error in punycode encoding") 184 | } 185 | 186 | // adapt is the bias adaptation function specified in section 6.1. 187 | func adapt(delta, numPoints int32, firstTime bool) int32 { 188 | if firstTime { 189 | delta /= damp 190 | } else { 191 | delta /= 2 192 | } 193 | delta += delta / numPoints 194 | k := int32(0) 195 | for delta > ((base-tmin)*tmax)/2 { 196 | delta /= base - tmin 197 | k += base 198 | } 199 | return k + (base-tmin+1)*delta/(delta+skew) 200 | } 201 | -------------------------------------------------------------------------------- /contact.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: contact.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package contact is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | contact.proto 10 | 11 | It has these top-level messages: 12 | Contact 13 | PhoneNumber 14 | */ 15 | package contact 16 | 17 | import proto "github.com/golang/protobuf/proto" 18 | import fmt "fmt" 19 | import math "math" 20 | 21 | // Reference imports to suppress errors if they are not otherwise used. 22 | var _ = proto.Marshal 23 | var _ = fmt.Errorf 24 | var _ = math.Inf 25 | 26 | // This is a compile-time assertion to ensure that this generated file 27 | // is compatible with the proto package it is being compiled against. 28 | // A compilation error at this line likely means your copy of the 29 | // proto package needs to be updated. 30 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 31 | 32 | type PhoneNumber_PhoneType int32 33 | 34 | const ( 35 | PhoneNumber_MOBILE PhoneNumber_PhoneType = 0 36 | PhoneNumber_HOME PhoneNumber_PhoneType = 1 37 | PhoneNumber_WORK PhoneNumber_PhoneType = 2 38 | ) 39 | 40 | var PhoneNumber_PhoneType_name = map[int32]string{ 41 | 0: "MOBILE", 42 | 1: "HOME", 43 | 2: "WORK", 44 | } 45 | var PhoneNumber_PhoneType_value = map[string]int32{ 46 | "MOBILE": 0, 47 | "HOME": 1, 48 | "WORK": 2, 49 | } 50 | 51 | func (x PhoneNumber_PhoneType) String() string { 52 | return proto.EnumName(PhoneNumber_PhoneType_name, int32(x)) 53 | } 54 | func (PhoneNumber_PhoneType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1, 0} } 55 | 56 | type Contact struct { 57 | Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` 58 | Email string `protobuf:"bytes,2,opt,name=email" json:"email,omitempty"` 59 | PhoneNumbers []*PhoneNumber `protobuf:"bytes,3,rep,name=phone_numbers,json=phoneNumbers" json:"phone_numbers,omitempty"` 60 | Home *PhoneNumber `protobuf:"bytes,4,opt,name=home" json:"home,omitempty"` 61 | Mobile *PhoneNumber `protobuf:"bytes,5,opt,name=mobile" json:"mobile,omitempty"` 62 | Work *PhoneNumber `protobuf:"bytes,6,opt,name=work" json:"work,omitempty"` 63 | } 64 | 65 | func (m *Contact) Reset() { *m = Contact{} } 66 | func (m *Contact) String() string { return proto.CompactTextString(m) } 67 | func (*Contact) ProtoMessage() {} 68 | func (*Contact) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 69 | 70 | func (m *Contact) GetPhoneNumbers() []*PhoneNumber { 71 | if m != nil { 72 | return m.PhoneNumbers 73 | } 74 | return nil 75 | } 76 | 77 | func (m *Contact) GetHome() *PhoneNumber { 78 | if m != nil { 79 | return m.Home 80 | } 81 | return nil 82 | } 83 | 84 | func (m *Contact) GetMobile() *PhoneNumber { 85 | if m != nil { 86 | return m.Mobile 87 | } 88 | return nil 89 | } 90 | 91 | func (m *Contact) GetWork() *PhoneNumber { 92 | if m != nil { 93 | return m.Work 94 | } 95 | return nil 96 | } 97 | 98 | type PhoneNumber struct { 99 | Number string `protobuf:"bytes,1,opt,name=number" json:"number,omitempty"` 100 | Type PhoneNumber_PhoneType `protobuf:"varint,2,opt,name=type,enum=contact.PhoneNumber_PhoneType" json:"type,omitempty"` 101 | } 102 | 103 | func (m *PhoneNumber) Reset() { *m = PhoneNumber{} } 104 | func (m *PhoneNumber) String() string { return proto.CompactTextString(m) } 105 | func (*PhoneNumber) ProtoMessage() {} 106 | func (*PhoneNumber) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } 107 | 108 | func init() { 109 | proto.RegisterType((*Contact)(nil), "contact.Contact") 110 | proto.RegisterType((*PhoneNumber)(nil), "contact.PhoneNumber") 111 | proto.RegisterEnum("contact.PhoneNumber_PhoneType", PhoneNumber_PhoneType_name, PhoneNumber_PhoneType_value) 112 | } 113 | 114 | func init() { proto.RegisterFile("contact.proto", fileDescriptor0) } 115 | 116 | var fileDescriptor0 = []byte{ 117 | // 249 bytes of a gzipped FileDescriptorProto 118 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0xce, 0xcf, 0x2b, 119 | 0x49, 0x4c, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x87, 0x72, 0x95, 0x3e, 0x30, 120 | 0x72, 0xb1, 0x3b, 0x43, 0xd8, 0x42, 0x42, 0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 121 | 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0xb6, 0x90, 0x08, 0x17, 0x6b, 0x6a, 0x6e, 0x62, 0x66, 0x8e, 0x04, 122 | 0x13, 0x58, 0x10, 0xc2, 0x11, 0xb2, 0xe4, 0xe2, 0x2d, 0xc8, 0xc8, 0xcf, 0x4b, 0x8d, 0xcf, 0x2b, 123 | 0xcd, 0x4d, 0x4a, 0x2d, 0x2a, 0x96, 0x60, 0x56, 0x60, 0xd6, 0xe0, 0x36, 0x12, 0xd1, 0x83, 0xd9, 124 | 0x12, 0x00, 0x92, 0xf5, 0x03, 0x4b, 0x06, 0xf1, 0x14, 0x20, 0x38, 0xc5, 0x42, 0x1a, 0x5c, 0x2c, 125 | 0x19, 0xf9, 0xb9, 0xa9, 0x12, 0x2c, 0x0a, 0x8c, 0x38, 0x75, 0x80, 0x55, 0x08, 0xe9, 0x70, 0xb1, 126 | 0xe5, 0xe6, 0x27, 0x65, 0xe6, 0xa4, 0x4a, 0xb0, 0xe2, 0x51, 0x0b, 0x55, 0x03, 0x32, 0xb7, 0x3c, 127 | 0xbf, 0x28, 0x5b, 0x82, 0x0d, 0x9f, 0xb9, 0x20, 0x15, 0x4a, 0x6d, 0x8c, 0x5c, 0xdc, 0x48, 0xa2, 128 | 0x42, 0x62, 0x5c, 0x6c, 0x10, 0x6f, 0x40, 0x3d, 0x0e, 0xe5, 0x09, 0x19, 0x71, 0xb1, 0x94, 0x54, 129 | 0x16, 0xa4, 0x82, 0x7d, 0xce, 0x67, 0x24, 0x87, 0xcd, 0x44, 0x08, 0x3b, 0xa4, 0xb2, 0x20, 0x35, 130 | 0x08, 0xac, 0x56, 0x49, 0x9b, 0x8b, 0x13, 0x2e, 0x24, 0xc4, 0xc5, 0xc5, 0xe6, 0xeb, 0xef, 0xe4, 131 | 0xe9, 0xe3, 0x2a, 0xc0, 0x20, 0xc4, 0xc1, 0xc5, 0xe2, 0xe1, 0xef, 0xeb, 0x2a, 0xc0, 0x08, 0x62, 132 | 0x85, 0xfb, 0x07, 0x79, 0x0b, 0x30, 0x25, 0xb1, 0x81, 0xe3, 0xc2, 0x18, 0x10, 0x00, 0x00, 0xff, 133 | 0xff, 0x9b, 0xec, 0x7d, 0xa3, 0x9c, 0x01, 0x00, 0x00, 134 | } 135 | --------------------------------------------------------------------------------