I'm looking for a condition check in Go which can terminate the program execution like assert in C++.
As mentioned by commenters, Go does not have assertions.
A comparable alternative in Go is the built-in function panic(...)
, gated by a condition:
if condition {
panic(err)
}
This article titled "Defer, Panic, and Recover" may also be informative.