Files
go-enum/example/go_enum_enum_test.go

47 lines
1.1 KiB
Go

// Code generated by go-enum DO NOT EDIT.
// Version: example
// Revision: example
// Build Date: example
// Built By: example
package example
import (
"errors"
"fmt"
)
const (
// TestOnlyEnumABCDX is a TestOnlyEnum of type ABCD (x).
TestOnlyEnumABCDX TestOnlyEnum = "ABCD (x)"
// TestOnlyEnumEFGHY is a TestOnlyEnum of type EFGH (y).
TestOnlyEnumEFGHY TestOnlyEnum = "EFGH (y)"
)
var ErrInvalidTestOnlyEnum = errors.New("not a valid TestOnlyEnum")
// String implements the Stringer interface.
func (x TestOnlyEnum) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x TestOnlyEnum) IsValid() bool {
_, err := ParseTestOnlyEnum(string(x))
return err == nil
}
var _TestOnlyEnumValue = map[string]TestOnlyEnum{
"ABCD (x)": TestOnlyEnumABCDX,
"EFGH (y)": TestOnlyEnumEFGHY,
}
// ParseTestOnlyEnum attempts to convert a string to a TestOnlyEnum.
func ParseTestOnlyEnum(name string) (TestOnlyEnum, error) {
if x, ok := _TestOnlyEnumValue[name]; ok {
return x, nil
}
return TestOnlyEnum(""), fmt.Errorf("%s is %w", name, ErrInvalidTestOnlyEnum)
}