1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00

remove dependencies to github.com/pkg/errors

This commit is contained in:
Jaana Burcu Dogan 2017-03-18 17:29:31 -07:00
parent b0c5c02b30
commit 62f833fc9f

11
cmd.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -12,7 +13,6 @@ import (
"github.com/google/gops/internal" "github.com/google/gops/internal"
"github.com/google/gops/signal" "github.com/google/gops/signal"
"github.com/pkg/errors"
) )
var cmds = map[string](func(addr net.TCPAddr) error){ var cmds = map[string](func(addr net.TCPAddr) error){
@ -102,10 +102,9 @@ func pprof(addr net.TCPAddr, p byte) error {
return err return err
} }
{ {
out, err := cmd(addr, signal.BinaryDump) out, err := cmd(addr, signal.BinaryDump)
if err != nil { if err != nil {
return errors.New("couldn't retrieve running binary's dump") return fmt.Errorf("failed to read the binary: %v", err)
} }
if len(out) == 0 { if len(out) == 0 {
return errors.New("failed to read the binary") return errors.New("failed to read the binary")
@ -144,14 +143,14 @@ func targetToAddr(target string) (*net.TCPAddr, error) {
var err error var err error
addr, err := net.ResolveTCPAddr("tcp", target) addr, err := net.ResolveTCPAddr("tcp", target)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "couldn't parse dst address") return nil, fmt.Errorf("couldn't parse dst address: %v", err)
} }
return addr, nil return addr, nil
} }
// try to find port by pid then, connect to local // try to find port by pid then, connect to local
pid, err := strconv.Atoi(target) pid, err := strconv.Atoi(target)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "couldn't parse PID") return nil, fmt.Errorf("couldn't parse PID: %v", err)
} }
port, err := internal.GetPort(pid) port, err := internal.GetPort(pid)
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port) addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:"+port)
@ -161,7 +160,7 @@ func targetToAddr(target string) (*net.TCPAddr, error) {
func cmd(addr net.TCPAddr, c byte) ([]byte, error) { func cmd(addr net.TCPAddr, c byte) ([]byte, error) {
conn, err := cmdLazy(addr, c) conn, err := cmdLazy(addr, c)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "couldn't get port by PID") return nil, fmt.Errorf("couldn't get port by PID: %v", err)
} }
all, err := ioutil.ReadAll(conn) all, err := ioutil.ReadAll(conn)