Files
mayfly-go/base/utils/assert/assert.go

22 lines
476 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package assert
import "fmt"
// 断言条件为真不满足的panic
func IsTrue(condition bool, panicMsg string, params ...interface{}) {
if !condition {
if len(params) != 0 {
panic(fmt.Sprintf(panicMsg, params...))
}
panic(panicMsg)
}
}
func State(condition bool, panicMsg string, params ...interface{}) {
IsTrue(condition, panicMsg, params...)
}
func NotEmpty(str string, panicMsg string, params ...interface{}) {
IsTrue(str != "", panicMsg, params...)
}