mirror of
https://github.com/abice/go-enum.git
synced 2026-10-29 00:56:10 +08:00
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
// Code generated by go-enum DO NOT EDIT.
|
|
// Version: example
|
|
// Revision: example
|
|
// Build Date: example
|
|
// Built By: example
|
|
|
|
//go:build example
|
|
// +build example
|
|
|
|
package example
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// AcmeInc_SOME_PLACE_AWESOME is a Shop of type SOME_PLACE_AWESOME.
|
|
AcmeInc_SOME_PLACE_AWESOME Shop = "SOME_PLACE_AWESOME"
|
|
// AcmeInc_SomewhereElse is a Shop of type SomewhereElse.
|
|
AcmeInc_SomewhereElse Shop = "SomewhereElse"
|
|
// AcmeInc_LocationUnknown is a Shop of type LocationUnknown.
|
|
AcmeInc_LocationUnknown Shop = "LocationUnknown"
|
|
)
|
|
|
|
var ErrInvalidShop = fmt.Errorf("not a valid Shop, try [%s]", strings.Join(_ShopNames, ", "))
|
|
|
|
var _ShopNames = []string{
|
|
string(AcmeInc_SOME_PLACE_AWESOME),
|
|
string(AcmeInc_SomewhereElse),
|
|
string(AcmeInc_LocationUnknown),
|
|
}
|
|
|
|
// ShopNames returns a list of possible string values of Shop.
|
|
func ShopNames() []string {
|
|
tmp := make([]string, len(_ShopNames))
|
|
copy(tmp, _ShopNames)
|
|
return tmp
|
|
}
|
|
|
|
// String implements the Stringer interface.
|
|
func (x Shop) 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 Shop) IsValid() bool {
|
|
_, err := ParseShop(string(x))
|
|
return err == nil
|
|
}
|
|
|
|
var _ShopValue = map[string]Shop{
|
|
"SOME_PLACE_AWESOME": AcmeInc_SOME_PLACE_AWESOME,
|
|
"SomewhereElse": AcmeInc_SomewhereElse,
|
|
"LocationUnknown": AcmeInc_LocationUnknown,
|
|
}
|
|
|
|
// ParseShop attempts to convert a string to a Shop.
|
|
func ParseShop(name string) (Shop, error) {
|
|
if x, ok := _ShopValue[name]; ok {
|
|
return x, nil
|
|
}
|
|
return Shop(""), fmt.Errorf("%s is %w", name, ErrInvalidShop)
|
|
}
|
|
|
|
// MarshalText implements the text marshaller method.
|
|
func (x Shop) MarshalText() ([]byte, error) {
|
|
return []byte(string(x)), nil
|
|
}
|
|
|
|
// UnmarshalText implements the text unmarshaller method.
|
|
func (x *Shop) UnmarshalText(text []byte) error {
|
|
tmp, err := ParseShop(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*x = tmp
|
|
return nil
|
|
}
|
|
|
|
// AppendText appends the textual representation of itself to the end of b
|
|
// (allocating a larger slice if necessary) and returns the updated slice.
|
|
//
|
|
// Implementations must not retain b, nor mutate any bytes within b[:len(b)].
|
|
func (x Shop) AppendText(b []byte) ([]byte, error) {
|
|
return append(b, x.String()...), nil
|
|
}
|