/
types_enum.go
73 lines (61 loc) · 1.82 KB
/
types_enum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Code generated by go-enum DO NOT EDIT.
// Version: 0.5.6
// Revision: 97611fddaa414f53713597918c5e954646cb8623
// Build Date: 2023-03-26T21:38:06Z
// Built By: goreleaser
package internal
import (
"fmt"
"strings"
)
const (
// RequestTypeHttp is a RequestType of type http.
RequestTypeHttp RequestType = "http"
// RequestTypeGrpc is a RequestType of type grpc.
RequestTypeGrpc RequestType = "grpc"
)
var ErrInvalidRequestType = fmt.Errorf("not a valid RequestType, try [%s]", strings.Join(_RequestTypeNames, ", "))
var _RequestTypeNames = []string{
string(RequestTypeHttp),
string(RequestTypeGrpc),
}
// RequestTypeNames returns a list of possible string values of RequestType.
func RequestTypeNames() []string {
tmp := make([]string, len(_RequestTypeNames))
copy(tmp, _RequestTypeNames)
return tmp
}
// String implements the Stringer interface.
func (x RequestType) 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 RequestType) IsValid() bool {
_, err := ParseRequestType(string(x))
return err == nil
}
var _RequestTypeValue = map[string]RequestType{
"http": RequestTypeHttp,
"grpc": RequestTypeGrpc,
}
// ParseRequestType attempts to convert a string to a RequestType.
func ParseRequestType(name string) (RequestType, error) {
if x, ok := _RequestTypeValue[name]; ok {
return x, nil
}
return RequestType(""), fmt.Errorf("%s is %w", name, ErrInvalidRequestType)
}
// MarshalText implements the text marshaller method.
func (x RequestType) MarshalText() ([]byte, error) {
return []byte(string(x)), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *RequestType) UnmarshalText(text []byte) error {
tmp, err := ParseRequestType(string(text))
if err != nil {
return err
}
*x = tmp
return nil
}