From b2090eb8fd1d74ba46b312df07e439e1a5a93d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 22 Mar 2024 11:36:48 +0100 Subject: [PATCH] Fix lints --- main.go | 14 +++++++------- subprocess.go | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 1de6cf5..0b25ac3 100644 --- a/main.go +++ b/main.go @@ -32,17 +32,17 @@ import ( ) func main() { - //parse command line + // parse command line portForwardArgs, subcommandArgs := splitArgs() - //setup async machinery - ctx, cancel := signal.NotifyContext(context.Background(), //once one subprocess returns, we cancel this ctx to reap the other one + // setup async machinery + ctx, cancel := signal.NotifyContext(context.Background(), // once one subprocess returns, we cancel this ctx to reap the other one os.Interrupt, syscall.SIGTERM) var wg sync.WaitGroup - errChan := make(chan error, 2) //collects errors from the subprocess; any error from one will terminate the whole program - portReadableChan := make(chan struct{}) //signals that the ports are established and the subcommand can start + errChan := make(chan error, 2) // collects errors from the subprocess; any error from one will terminate the whole program + portReadableChan := make(chan struct{}) // signals that the ports are established and the subcommand can start - //run subprocesses + // run subprocesses wg.Add(2) go func() { defer wg.Done() @@ -53,7 +53,7 @@ func main() { runSubcommand(ctx, subcommandArgs, errChan, portReadableChan) }() - //once either exits, cancel the other + // once either exits, cancel the other err := <-errChan cancel() wg.Wait() diff --git a/subprocess.go b/subprocess.go index 0dc92f4..a5682cd 100644 --- a/subprocess.go +++ b/subprocess.go @@ -43,7 +43,7 @@ func runKubectlPortForward(ctx context.Context, args []string, errChan chan<- er cmd.Cancel = func() error { return cmd.Process.Signal(os.Interrupt) } cmd.WaitDelay = 3 * time.Second cmd.Stdin = nil - cmd.Stdout = stderr //os.Stdout is exclusively reserved for the actual payload command + cmd.Stdout = stderr // os.Stdout is exclusively reserved for the actual payload command cmd.Stderr = stderr errChan <- cmd.Run() } @@ -58,7 +58,7 @@ type portReadableDetector struct { func (d *portReadableDetector) Write(buf []byte) (int, error) { if !d.done && bytes.Contains(buf, []byte("Forwarding from")) { go func() { - //give kubectl some extra time if it needs to listen on multiple ports + // give kubectl some extra time if it needs to listen on multiple ports time.Sleep(25 * time.Microsecond) close(d.portReadableChan) }() @@ -68,11 +68,11 @@ func (d *portReadableDetector) Write(buf []byte) (int, error) { } func runSubcommand(ctx context.Context, cmdline []string, errChan chan<- error, portReadableChan <-chan struct{}) { - //wait for either the port-forward to become active, or for the port-forward - //failing and its failure being signaled to us by canceling `ctx` + // wait for either the port-forward to become active, or for the port-forward + // failing and its failure being signaled to us by canceling `ctx` select { case <-portReadableChan: - //continue below + // continue below case <-ctx.Done(): return }