Skip to content

colbee1/assertor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

assertor

Assertor is a tiny golang helper to quickly validate parameters.

How to use it

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
}

About

assertor is a tiny golang helper to quickly validate input parameters

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages