This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
samesite_enumer.go
69 lines (56 loc) · 1.74 KB
/
samesite_enumer.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
// Code generated by "enumer --type=SameSite --trimprefix=SameSite -json"; DO NOT EDIT.
package config
import (
"encoding/json"
"fmt"
)
const _SameSiteName = "DefaultModeLaxModeStrictModeNoneMode"
var _SameSiteIndex = [...]uint8{0, 11, 18, 28, 36}
func (i SameSite) String() string {
if i < 0 || i >= SameSite(len(_SameSiteIndex)-1) {
return fmt.Sprintf("SameSite(%d)", i)
}
return _SameSiteName[_SameSiteIndex[i]:_SameSiteIndex[i+1]]
}
var _SameSiteValues = []SameSite{0, 1, 2, 3}
var _SameSiteNameToValueMap = map[string]SameSite{
_SameSiteName[0:11]: 0,
_SameSiteName[11:18]: 1,
_SameSiteName[18:28]: 2,
_SameSiteName[28:36]: 3,
}
// SameSiteString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func SameSiteString(s string) (SameSite, error) {
if val, ok := _SameSiteNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to SameSite values", s)
}
// SameSiteValues returns all values of the enum
func SameSiteValues() []SameSite {
return _SameSiteValues
}
// IsASameSite returns "true" if the value is listed in the enum definition. "false" otherwise
func (i SameSite) IsASameSite() bool {
for _, v := range _SameSiteValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for SameSite
func (i SameSite) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for SameSite
func (i *SameSite) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("SameSite should be a string, got %s", data)
}
var err error
*i, err = SameSiteString(s)
return err
}