packagesystemimport("fmt""os/exec""syscall")// GetExitCode returns the ExitStatus of the specified error if its type is// exec.ExitError, returns 0 and an error otherwise.funcGetExitCode(errerror)(int,error){exitCode:=0ifexiterr,ok:=err.(*exec.ExitError);ok{ifprocExit,ok:=exiterr.Sys().(syscall.WaitStatus);ok{returnprocExit.ExitStatus(),nil}}returnexitCode,fmt.Errorf("failed to get exit code")}// ProcessExitCode process the specified error and returns the exit status code// if the error was of type exec.ExitError, returns nothing otherwise.funcProcessExitCode(errerror)(exitCodeint){iferr!=nil{varexiterrerrorifexitCode,exiterr=GetExitCode(err);exiterr!=nil{// TODO: Fix this so we check the error's text.// we've failed to retrieve exit code, so we set it to 127exitCode=127}}return}