Is there something in Go which do just opposite to what init()
do inside a package?
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
- IntelliJ 2017.1.2 GOLANG debug does not work on br
相关文章
- Can I run a single test in a suite?
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- How to access value of first index of array in Go
- Embedded Interface
- How to represent an array with mixed types
- Java -How to get logger to work in shutdown hook?
- go tutorial select statement
This was discussed before by the Go team, and the conclusion was not to add support for it. Quoting minux:
But you still have some options:
Handling CTRL+C
If you want to do something when your program is terminated by CTRL+C (SIGINT), you can do so, see:
Golang: Is it possible to capture a Ctrl+C signal and run a cleanup function, in a "defer" fashion?
Object Finalizer
Also note that you can register a finalizer function for a pointer value. When the garbage collector finds an unreachable block with an associated finalizer, it clears the association and runs
f(x)
in a separate goroutine.You can register such finalizer with
runtime.SetFinalizer()
which might be enough for you, but note:See this example:
Output (Go Playground):