2021-07-28 18:03:19 +08:00
|
|
|
|
package assert
|
|
|
|
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
|
|
|
|
// 断言条件为真,不满足的panic
|
2023-05-24 12:32:17 +08:00
|
|
|
|
func IsTrue(condition bool, panicMsg string, params ...any) {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
if !condition {
|
|
|
|
|
|
if len(params) != 0 {
|
|
|
|
|
|
panic(fmt.Sprintf(panicMsg, params...))
|
|
|
|
|
|
}
|
|
|
|
|
|
panic(panicMsg)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-24 12:32:17 +08:00
|
|
|
|
func State(condition bool, panicMsg string, params ...any) {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
IsTrue(condition, panicMsg, params...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-24 12:32:17 +08:00
|
|
|
|
func NotEmpty(str string, panicMsg string, params ...any) {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
IsTrue(str != "", panicMsg, params...)
|
|
|
|
|
|
}
|