Simple example how to run external program from golang with context timeout:

package utils

import (
	"context"
	"fmt"
	"os/exec"
	"time"
)

//RunExternalCmd run external command with timeout
func RunExternalCmd(commandToRun string, defaultTimeOutMinutes time.Duration) (string, error) {
	ctx, cancel := context.WithTimeout(context.Background(), defaultTimeOutMinutes*time.Minute)
	defer cancel()
	DebugMsg(0, fmt.Sprintf("running command: %s", commandToRun))
	cmd := exec.CommandContext(ctx, "bash", "-c", commandToRun)
	output, err := cmd.CombinedOutput()
	if ctx.Err() == context.DeadlineExceeded {
		err = fmt.Errorf("Command timed out: ", err)
	}
	return string(output), err
}