common.go 817 B

123456789101112131415161718192021222324252627282930
  1. // Package common contains common utilities that are shared among other packages.
  2. // See each sub-package for detail.
  3. package common
  4. import "v2ray.com/core/common/errors"
  5. //go:generate errorgen
  6. var (
  7. // ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.
  8. ErrNoClue = errors.New("not enough information for making a decision")
  9. )
  10. // Must panics if err is not nil.
  11. func Must(err error) {
  12. if err != nil {
  13. panic(err)
  14. }
  15. }
  16. // Must2 panics if the second parameter is not nil, otherwise returns the first parameter.
  17. func Must2(v interface{}, err error) interface{} {
  18. Must(err)
  19. return v
  20. }
  21. // Error2 returns the err from the 2nd parameter.
  22. func Error2(v interface{}, err error) error {
  23. return err
  24. }