github.com/itsabgr/go-handy@v0.0.0-20220724000257-022d51f2b9c6/assert.go (about)

     1  package handy
     2  
     3  import "errors"
     4  
     5  //ErrAssertion is an assertion failed error
     6  var ErrAssertion = errors.New("assertion")
     7  
     8  //Assert panic WhatWillPanic for ErrAssertion if value is false
     9  func Assert(value bool, WhatWillPanic ...interface{}) {
    10  	if !value {
    11  		if len(WhatWillPanic) == 0 || WhatWillPanic[0] == nil {
    12  			panic(ErrAssertion)
    13  		}
    14  		panic(WhatWillPanic[0])
    15  	}
    16  }