replace pkg/errors from vendor
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
This commit is contained in:
		| @@ -19,11 +19,11 @@ package ttrpc | |||||||
| import ( | import ( | ||||||
| 	"bufio" | 	"bufio" | ||||||
| 	"encoding/binary" | 	"encoding/binary" | ||||||
|  | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"net" | 	"net" | ||||||
| 	"sync" | 	"sync" | ||||||
|  |  | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
| ) | ) | ||||||
| @@ -105,7 +105,7 @@ func (ch *channel) recv() (messageHeader, []byte, error) { | |||||||
|  |  | ||||||
| 	if mh.Length > uint32(messageLengthMax) { | 	if mh.Length > uint32(messageLengthMax) { | ||||||
| 		if _, err := ch.br.Discard(int(mh.Length)); err != nil { | 		if _, err := ch.br.Discard(int(mh.Length)); err != nil { | ||||||
| 			return mh, nil, errors.Wrapf(err, "failed to discard after receiving oversized message") | 			return mh, nil, fmt.Errorf("failed to discard after receiving oversized message: %w", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return mh, nil, status.Errorf(codes.ResourceExhausted, "message length %v exceed maximum message size of %v", mh.Length, messageLengthMax) | 		return mh, nil, status.Errorf(codes.ResourceExhausted, "message length %v exceed maximum message size of %v", mh.Length, messageLengthMax) | ||||||
| @@ -113,7 +113,7 @@ func (ch *channel) recv() (messageHeader, []byte, error) { | |||||||
|  |  | ||||||
| 	p := ch.getmbuf(int(mh.Length)) | 	p := ch.getmbuf(int(mh.Length)) | ||||||
| 	if _, err := io.ReadFull(ch.br, p); err != nil { | 	if _, err := io.ReadFull(ch.br, p); err != nil { | ||||||
| 		return messageHeader{}, nil, errors.Wrapf(err, "failed reading message") | 		return messageHeader{}, nil, fmt.Errorf("failed reading message: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return mh, p, nil | 	return mh, p, nil | ||||||
|   | |||||||
| @@ -18,12 +18,12 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
|  | 	"errors" | ||||||
| 	"io" | 	"io" | ||||||
| 	"net" | 	"net" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
| ) | ) | ||||||
| @@ -56,7 +56,7 @@ func TestReadWriteMessage(t *testing.T) { | |||||||
| 	for { | 	for { | ||||||
| 		_, p, err := rch.recv() | 		_, p, err := rch.recv() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			if errors.Cause(err) != io.EOF { | 			if !errors.Is(err, io.EOF) { | ||||||
| 				t.Fatal(err) | 				t.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
| 	"io" | 	"io" | ||||||
| 	"net" | 	"net" | ||||||
| 	"os" | 	"os" | ||||||
| @@ -27,7 +28,6 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/gogo/protobuf/proto" | 	"github.com/gogo/protobuf/proto" | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
| @@ -347,7 +347,7 @@ func filterCloseErr(err error) error { | |||||||
| 		return nil | 		return nil | ||||||
| 	case err == io.EOF: | 	case err == io.EOF: | ||||||
| 		return ErrClosed | 		return ErrClosed | ||||||
| 	case errors.Cause(err) == io.EOF: | 	case errors.Is(err, io.EOF): | ||||||
| 		return ErrClosed | 		return ErrClosed | ||||||
| 	case strings.Contains(err.Error(), "use of closed network connection"): | 	case strings.Contains(err.Error(), "use of closed network connection"): | ||||||
| 		return ErrClosed | 		return ErrClosed | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								codec.go
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								codec.go
									
									
									
									
									
								
							| @@ -17,8 +17,9 @@ | |||||||
| package ttrpc | package ttrpc | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
| 	"github.com/gogo/protobuf/proto" | 	"github.com/gogo/protobuf/proto" | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type codec struct{} | type codec struct{} | ||||||
| @@ -28,7 +29,7 @@ func (c codec) Marshal(msg interface{}) ([]byte, error) { | |||||||
| 	case proto.Message: | 	case proto.Message: | ||||||
| 		return proto.Marshal(v) | 		return proto.Marshal(v) | ||||||
| 	default: | 	default: | ||||||
| 		return nil, errors.Errorf("ttrpc: cannot marshal unknown type: %T", msg) | 		return nil, fmt.Errorf("ttrpc: cannot marshal unknown type: %T", msg) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -37,6 +38,6 @@ func (c codec) Unmarshal(p []byte, msg interface{}) error { | |||||||
| 	case proto.Message: | 	case proto.Message: | ||||||
| 		return proto.Unmarshal(p, v) | 		return proto.Unmarshal(p, v) | ||||||
| 	default: | 	default: | ||||||
| 		return errors.Errorf("ttrpc: cannot unmarshal into unknown type: %T", msg) | 		return fmt.Errorf("ttrpc: cannot unmarshal into unknown type: %T", msg) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ | |||||||
|  |  | ||||||
| package ttrpc | package ttrpc | ||||||
|  |  | ||||||
| import "github.com/pkg/errors" | import "errors" | ||||||
|  |  | ||||||
| type serverConfig struct { | type serverConfig struct { | ||||||
| 	handshaker  Handshaker | 	handshaker  Handshaker | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								go.mod
									
									
									
									
									
								
							| @@ -4,9 +4,8 @@ go 1.13 | |||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/gogo/protobuf v1.3.2 | 	github.com/gogo/protobuf v1.3.2 | ||||||
| 	github.com/pkg/errors v0.9.1 |  | ||||||
| 	github.com/prometheus/procfs v0.6.0 | 	github.com/prometheus/procfs v0.6.0 | ||||||
| 	github.com/sirupsen/logrus v1.7.0 | 	github.com/sirupsen/logrus v1.8.1 | ||||||
| 	golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c | 	golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c | ||||||
| 	google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63 | 	google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63 | ||||||
| 	google.golang.org/grpc v1.27.1 | 	google.golang.org/grpc v1.27.1 | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								go.sum
									
									
									
									
									
								
							| @@ -20,15 +20,13 @@ github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= | |||||||
| github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||||
| github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= | ||||||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||||||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= |  | ||||||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= |  | ||||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||||
| github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= | ||||||
| github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= | github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= | ||||||
| github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= | github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= | ||||||
| github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= | github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= | ||||||
| github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= | github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= | ||||||
| github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||||||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||||||
| github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
| 	"io" | 	"io" | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"net" | 	"net" | ||||||
| @@ -25,7 +26,6 @@ import ( | |||||||
| 	"sync/atomic" | 	"sync/atomic" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net" | 	"net" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| @@ -28,7 +29,6 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/gogo/protobuf/proto" | 	"github.com/gogo/protobuf/proto" | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
| ) | ) | ||||||
| @@ -361,8 +361,8 @@ func TestClientEOF(t *testing.T) { | |||||||
| 	// server shutdown, but we still make a call. | 	// server shutdown, but we still make a call. | ||||||
| 	if err := client.Call(ctx, serviceName, "Test", tp, tp); err == nil { | 	if err := client.Call(ctx, serviceName, "Test", tp, tp); err == nil { | ||||||
| 		t.Fatalf("expected error when calling against shutdown server") | 		t.Fatalf("expected error when calling against shutdown server") | ||||||
| 	} else if errors.Cause(err) != ErrClosed { | 	} else if !errors.Is(err, ErrClosed) { | ||||||
| 		t.Fatalf("expected to have a cause of ErrClosed, got %v", errors.Cause(err)) | 		t.Fatalf("expected to have a cause of ErrClosed, got %v", err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,13 +18,14 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"unsafe" | 	"unsafe" | ||||||
|  |  | ||||||
| 	"github.com/gogo/protobuf/proto" | 	"github.com/gogo/protobuf/proto" | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"google.golang.org/grpc/codes" | 	"google.golang.org/grpc/codes" | ||||||
| 	"google.golang.org/grpc/status" | 	"google.golang.org/grpc/status" | ||||||
| ) | ) | ||||||
| @@ -51,7 +52,7 @@ func newServiceSet(interceptor UnaryServerInterceptor) *serviceSet { | |||||||
|  |  | ||||||
| func (s *serviceSet) register(name string, methods map[string]Method) { | func (s *serviceSet) register(name string, methods map[string]Method) { | ||||||
| 	if _, ok := s.services[name]; ok { | 	if _, ok := s.services[name]; ok { | ||||||
| 		panic(errors.Errorf("duplicate service %v registered", name)) | 		panic(fmt.Errorf("duplicate service %v registered", name)) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	s.services[name] = ServiceDesc{ | 	s.services[name] = ServiceDesc{ | ||||||
|   | |||||||
| @@ -18,11 +18,12 @@ package ttrpc | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
| 	"net" | 	"net" | ||||||
| 	"os" | 	"os" | ||||||
| 	"syscall" | 	"syscall" | ||||||
|  |  | ||||||
| 	"github.com/pkg/errors" |  | ||||||
| 	"golang.org/x/sys/unix" | 	"golang.org/x/sys/unix" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -31,12 +32,12 @@ type UnixCredentialsFunc func(*unix.Ucred) error | |||||||
| func (fn UnixCredentialsFunc) Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) { | func (fn UnixCredentialsFunc) Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) { | ||||||
| 	uc, err := requireUnixSocket(conn) | 	uc, err := requireUnixSocket(conn) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, nil, errors.Wrap(err, "ttrpc.UnixCredentialsFunc: require unix socket") | 		return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: require unix socket: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	rs, err := uc.SyscallConn() | 	rs, err := uc.SyscallConn() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, nil, errors.Wrap(err, "ttrpc.UnixCredentialsFunc: (net.UnixConn).SyscallConn failed") | 		return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: (net.UnixConn).SyscallConn failed: %w", err) | ||||||
| 	} | 	} | ||||||
| 	var ( | 	var ( | ||||||
| 		ucred    *unix.Ucred | 		ucred    *unix.Ucred | ||||||
| @@ -45,15 +46,15 @@ func (fn UnixCredentialsFunc) Handshake(ctx context.Context, conn net.Conn) (net | |||||||
| 	if err := rs.Control(func(fd uintptr) { | 	if err := rs.Control(func(fd uintptr) { | ||||||
| 		ucred, ucredErr = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) | 		ucred, ucredErr = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED) | ||||||
| 	}); err != nil { | 	}); err != nil { | ||||||
| 		return nil, nil, errors.Wrapf(err, "ttrpc.UnixCredentialsFunc: (*syscall.RawConn).Control failed") | 		return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: (*syscall.RawConn).Control failed: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if ucredErr != nil { | 	if ucredErr != nil { | ||||||
| 		return nil, nil, errors.Wrapf(err, "ttrpc.UnixCredentialsFunc: failed to retrieve socket peer credentials") | 		return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: failed to retrieve socket peer credentials: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err := fn(ucred); err != nil { | 	if err := fn(ucred); err != nil { | ||||||
| 		return nil, nil, errors.Wrapf(err, "ttrpc.UnixCredentialsFunc: credential check failed") | 		return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: credential check failed: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return uc, ucred, nil | 	return uc, ucred, nil | ||||||
| @@ -93,7 +94,7 @@ func requireRoot(ucred *unix.Ucred) error { | |||||||
|  |  | ||||||
| func requireUidGid(ucred *unix.Ucred, uid, gid int) error { | func requireUidGid(ucred *unix.Ucred, uid, gid int) error { | ||||||
| 	if (uid != -1 && uint32(uid) != ucred.Uid) || (gid != -1 && uint32(gid) != ucred.Gid) { | 	if (uid != -1 && uint32(uid) != ucred.Uid) || (gid != -1 && uint32(gid) != ucred.Gid) { | ||||||
| 		return errors.Wrap(syscall.EPERM, "ttrpc: invalid credentials") | 		return fmt.Errorf("ttrpc: invalid credentials: %v", syscall.EPERM) | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zounengren
					zounengren