blocky/log/logger_enum.go

87 lines
2.0 KiB
Go

// Code generated by go-enum DO NOT EDIT.
// Version:
// Revision:
// Build Date:
// Built By:
package log
import (
"fmt"
"strings"
)
const (
// FormatTypeText is a FormatType of type Text.
// logging as text
FormatTypeText FormatType = iota
// FormatTypeJson is a FormatType of type Json.
// JSON format
FormatTypeJson
)
var ErrInvalidFormatType = fmt.Errorf("not a valid FormatType, try [%s]", strings.Join(_FormatTypeNames, ", "))
const _FormatTypeName = "textjson"
var _FormatTypeNames = []string{
_FormatTypeName[0:4],
_FormatTypeName[4:8],
}
// FormatTypeNames returns a list of possible string values of FormatType.
func FormatTypeNames() []string {
tmp := make([]string, len(_FormatTypeNames))
copy(tmp, _FormatTypeNames)
return tmp
}
var _FormatTypeMap = map[FormatType]string{
FormatTypeText: _FormatTypeName[0:4],
FormatTypeJson: _FormatTypeName[4:8],
}
// String implements the Stringer interface.
func (x FormatType) String() string {
if str, ok := _FormatTypeMap[x]; ok {
return str
}
return fmt.Sprintf("FormatType(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x FormatType) IsValid() bool {
_, ok := _FormatTypeMap[x]
return ok
}
var _FormatTypeValue = map[string]FormatType{
_FormatTypeName[0:4]: FormatTypeText,
_FormatTypeName[4:8]: FormatTypeJson,
}
// ParseFormatType attempts to convert a string to a FormatType.
func ParseFormatType(name string) (FormatType, error) {
if x, ok := _FormatTypeValue[name]; ok {
return x, nil
}
return FormatType(0), fmt.Errorf("%s is %w", name, ErrInvalidFormatType)
}
// MarshalText implements the text marshaller method.
func (x FormatType) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *FormatType) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseFormatType(name)
if err != nil {
return err
}
*x = tmp
return nil
}