Assertor is a tiny golang helper to quickly validate parameters.
Create a new assertor
v := assertor.New()Make assertions on input parameters
v.Assert(limit > 0, "invalid limit: %d", limit)
v.Assert(stop > 0 && stop > start, "inconsistant stop value: %v", stop)
v.Assert(ctx != nil, "context is missing")Validate
err := v.Validate()Full example
func Example(ctx context.Context, start int, stop int, limit int) error {
v := assertor.New()
v.Assert(limit > 0, "invalid limit: %d", limit)
v.Assert(stop > 0 && stop > start, "inconsistant stop value: %d", stop)
v.Assert(ctx != nil, "context is missing")
if err := v.Validate(); err != nil {
return err
}
/* some code */
return nil
}