Files
mayfly-go/server/pkg/utils/assert/assert.go

22 lines
452 B
Go
Raw Normal View History

package assert
import "fmt"
// 断言条件为真不满足的panic
2023-05-24 12:32:17 +08:00
func IsTrue(condition bool, panicMsg string, params ...any) {
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) {
IsTrue(condition, panicMsg, params...)
}
2023-05-24 12:32:17 +08:00
func NotEmpty(str string, panicMsg string, params ...any) {
IsTrue(str != "", panicMsg, params...)
}