mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-10 11:20:24 +08:00
22 lines
452 B
Go
22 lines
452 B
Go
package assert
|
||
|
||
import "fmt"
|
||
|
||
// 断言条件为真,不满足的panic
|
||
func IsTrue(condition bool, panicMsg string, params ...any) {
|
||
if !condition {
|
||
if len(params) != 0 {
|
||
panic(fmt.Sprintf(panicMsg, params...))
|
||
}
|
||
panic(panicMsg)
|
||
}
|
||
}
|
||
|
||
func State(condition bool, panicMsg string, params ...any) {
|
||
IsTrue(condition, panicMsg, params...)
|
||
}
|
||
|
||
func NotEmpty(str string, panicMsg string, params ...any) {
|
||
IsTrue(str != "", panicMsg, params...)
|
||
}
|