I'm implement a function that would call an interrupt signal in Go, using something like this for capturing interrupt signal

1
2
3
4
var stopChan = make(chan os.Signal, 2)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)

<-stopChan // wait for SIGINT

Use below from anywhere in your code to send interrupt signal to above wait part.

1
syscall.Kill(syscall.Getpid(), syscall.SIGINT)

Or if you are in the same package where where stopChan variable is defined. Thus making it accessible. You can do this.

1
stopChan <- syscall.SIGINT

Or you can define stopChan as a global variable (making the first letter in Capital letter will achieve the same), then you can send interrupt signal from a different package too.

1
Stopchan <- syscall.SIGINT