Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeTrue ¶
func BeTrue(ok bool)
Example ¶
package main
import (
"fmt"
"github.com/xoctopus/x/misc/must"
)
func ReturnTrue() bool {
return true
}
func ReturnFalse() bool {
return false
}
func main() {
must.BeTrue(ReturnTrue())
defer func() {
fmt.Println(recover())
}()
must.BeTrue(ReturnFalse())
}
Output: must be true
func BeTrueV ¶
Example ¶
package main
import (
"fmt"
"github.com/xoctopus/x/misc/must"
)
func ReturnIntTrue() (int, bool) {
return 100, true
}
func ReturnIntFalse() (int, bool) {
return 100, false
}
func main() {
fmt.Println(must.BeTrueV(ReturnIntTrue()))
defer func() {
fmt.Println(recover())
}()
_ = must.BeTrueV(ReturnIntFalse())
}
Output: 100 must be true
func BeTrueWrap ¶
Example ¶
package main
import (
"fmt"
"github.com/xoctopus/x/misc/must"
)
func ReturnTrue() bool {
return true
}
func ReturnFalse() bool {
return false
}
func main() {
must.BeTrueWrap(ReturnTrue(), "any")
defer func() {
fmt.Println(recover())
}()
must.BeTrueWrap(ReturnFalse(), "required exists")
}
Output: must be true: required exists
func NoError ¶
func NoError(err error)
Example ¶
package main
import (
"fmt"
"github.com/pkg/errors"
"github.com/xoctopus/x/misc/must"
)
func ReturnError() error {
return errors.New("some error")
}
func ReturnNoError() error {
return nil
}
func main() {
must.NoError(ReturnNoError())
defer func() {
fmt.Println(recover())
}()
must.NoError(ReturnError())
}
Output: some error
func NoErrorV ¶
Example ¶
package main
import (
"fmt"
"github.com/pkg/errors"
"github.com/xoctopus/x/misc/must"
)
func ReturnIntError() (int, error) {
return 100, errors.New("some error")
}
func ReturnIntNoError() (int, error) {
return 100, nil
}
func main() {
fmt.Println(must.NoErrorV(ReturnIntNoError()))
defer func() {
fmt.Println(recover())
}()
must.NoErrorV(ReturnIntError())
}
Output: 100 some error
func NoErrorWrap ¶
Example ¶
package main
import (
"fmt"
"github.com/pkg/errors"
"github.com/xoctopus/x/misc/must"
)
func ReturnError() error {
return errors.New("some error")
}
func ReturnNoError() error {
return nil
}
func main() {
must.NoErrorWrap(ReturnNoError(), "any")
defer func() {
fmt.Println(recover())
}()
must.NoErrorWrap(ReturnError(), "some message: %d", 10)
}
Output: some message: 10: some error
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.