Skip to content

Support for generated "MustParse" which panics on unknown values #76

@eligold94

Description

@eligold94

#79

The following is an example of what is currently generated:

// ParseFoo attempts to convert a string to a Foo
func ParseFoo(name string) (Foo, error) {
	if x, ok := _FooValue[name]; ok {
		return x, nil
	}
	return Foo(0), fmt.Errorf("%s is not a valid Foo", name)
}

To ease in a common use case of wanting to panic on an error, consider also generating (behind a flag -must?) the following:

// MustParseFoo attempts to convert a string to a Foo, panicking if unknown.
func MustParseFoo(name string) Foo {
    x, err := ParseFoo(name)
    if err != nil {
        panic(err)
    }
    return x
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions