gen_must

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 7 Imported by: 0

README

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
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL