Skip to content

gen_must is a go tool used to auto-generate Must* (or must*) function wrappers

License

Notifications You must be signed in to change notification settings

heliorosa/gen_must

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gen_must

gen_must is a go tool used to auto-generate Must* (or must*) function wrappers by simply marking the function with a comment tag //@gen_must.

syntax:

gen_must [-out filename] file_0.go file_1.go ... file_n.go

example:

Given a file decrement.go with the function:

package decrement

func DecrementUInt(v uint) (uint, error) {
    //@gen_must
	if v == 0 {
		return 0, errors.New("value is zero")
	}
	return v - 1, nil
}

And running:

gen_must -out musts.gen.go decrement.go

Generates the file musts.gen.go, with the content:

// Code generated - DO NOT EDIT.
// This file is auto generated by gen_must and any manual changes will be lost.

package decrement

// MustDecrementUInt has the behavior of DecrementUInt, except it panics on error
func MustDecrementUInt(v uint) uint {
        var0, err := DecrementUInt(v)
        if err != nil {
                panic(err)
        }
        return var0
}

gen_must can also generate wrappers for private functions and methods.

To customize the name of the generated function with the syntax: //@gen_must: newName

package decrement

func DecrementUInt(v uint) (uint, error) {
    //@gen_must: PanicOnFailToDecrementUInt
	if v == 0 {
		return 0, errors.New("value is zero")
	}
	return v - 1, nil
}

Results in:

// Code generated - DO NOT EDIT.
// This file is auto generated by gen_must and any manual changes will be lost.

package decrement

// PanicOnFailToDecrementUInt has the behavior of DecrementUInt, except it panics on error
func PanicOnFailToDecrementUInt(v uint) uint {
        var0, err := DecrementUInt(v)
        if err != nil {
                panic(err)
        }
        return var0
}

About

gen_must is a go tool used to auto-generate Must* (or must*) function wrappers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages