Answer the question
In order to leave comments, you need to log in
How to display a message at the end of a program?
We admit eats such simple code.
func main() {
fmt.Println("start")
defer func() {
fmt.Println("stop")
}()
Run()
fmt.Scanln()
}
Answer the question
In order to leave comments, you need to log in
To do this, you need to catch signals
https://gobyexample.com/signals
When the container stops, a SIGINT is sent to the program. It is necessary to catch it and correctly close the program.
defer is not used for this, but to ensure that some code is executed on return from a function or panic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question