blocky/log/logger_enum.go

87 lines
2.0 KiB
Go
Raw Normal View History

2021-09-09 22:57:05 +02:00
// 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, ", "))
2021-09-09 22:57:05 +02:00
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{
2022-03-28 21:35:48 +02:00
FormatTypeText: _FormatTypeName[0:4],
FormatTypeJson: _FormatTypeName[4:8],
2021-09-09 22:57:05 +02:00
}
// 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
}
2021-09-09 22:57:05 +02:00
var _FormatTypeValue = map[string]FormatType{
2022-03-28 21:35:48 +02:00
_FormatTypeName[0:4]: FormatTypeText,
_FormatTypeName[4:8]: FormatTypeJson,
2021-09-09 22:57:05 +02:00
}
2022-03-28 21:35:48 +02:00
// ParseFormatType attempts to convert a string to a FormatType.
2021-09-09 22:57:05 +02:00
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)
2021-09-09 22:57:05 +02:00
}
2022-03-28 21:35:48 +02:00
// MarshalText implements the text marshaller method.
2021-09-09 22:57:05 +02:00
func (x FormatType) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
2022-03-28 21:35:48 +02:00
// UnmarshalText implements the text unmarshaller method.
2021-09-09 22:57:05 +02:00
func (x *FormatType) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := ParseFormatType(name)
if err != nil {
return err
}
*x = tmp
return nil
}