1
0
mirror of https://github.com/google/gops.git synced 2024-11-19 20:31:58 +02:00

Remove named returns

Named returns should only be used with naked returns, or a
deferred function. And in general are better avoided
This commit is contained in:
Glib Smaga 2023-10-05 08:16:52 -07:00 committed by Tobias Klauser
parent 710ef44cc3
commit 22cdba11b7
2 changed files with 7 additions and 4 deletions

View File

@ -75,7 +75,7 @@ type Options struct {
// Note: The agent exposes an endpoint via a TCP connection that can be used by // Note: The agent exposes an endpoint via a TCP connection that can be used by
// any program on the system. Review your security requirements before starting // any program on the system. Review your security requirements before starting
// the agent. // the agent.
func Listen(opts Options) (err error) { func Listen(opts Options) error {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@ -87,10 +87,13 @@ func Listen(opts Options) (err error) {
if addr == "" { if addr == "" {
addr = defaultAddr addr = defaultAddr
} }
var lc net.ListenConfig var lc net.ListenConfig
if opts.ReuseSocketAddrAndPort { if opts.ReuseSocketAddrAndPort {
lc.Control = setReuseAddrAndPortSockopts lc.Control = setReuseAddrAndPortSockopts
} }
var err error
listener, err = lc.Listen(context.Background(), "tcp", addr) listener, err = lc.Listen(context.Background(), "tcp", addr)
if err != nil { if err != nil {
return err return err
@ -135,7 +138,7 @@ func listen(l net.Listener) {
} }
} }
func saveConfig(opts Options, port int) (err error) { func saveConfig(opts Options, port int) error {
gopsdir := opts.ConfigDir gopsdir := opts.ConfigDir
if gopsdir == "" { if gopsdir == "" {
cfgDir, err := internal.ConfigDir() cfgDir, err := internal.ConfigDir()
@ -145,7 +148,7 @@ func saveConfig(opts Options, port int) (err error) {
gopsdir = cfgDir gopsdir = cfgDir
} }
err = os.MkdirAll(gopsdir, os.ModePerm) err := os.MkdirAll(gopsdir, os.ModePerm)
if errors.Is(err, syscall.EROFS) || errors.Is(err, syscall.EPERM) { // ignore and work in remote mode only if errors.Is(err, syscall.EROFS) || errors.Is(err, syscall.EPERM) { // ignore and work in remote mode only
return nil return nil
} }

View File

@ -94,7 +94,7 @@ func findAll(pss []*process.Process, isGo isGoFunc, concurrencyLimit int) []P {
} }
// Find finds info about the process identified with the given PID. // Find finds info about the process identified with the given PID.
func Find(pid int) (p P, ok bool, err error) { func Find(pid int) (P, bool, error) {
pr, err := process.NewProcess(int32(pid)) pr, err := process.NewProcess(int32(pid))
if err != nil { if err != nil {
return P{}, false, err return P{}, false, err