forked from lestrrat-go/jwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompression_gen.go
73 lines (62 loc) · 2.01 KB
/
compression_gen.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
// this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
package jwa
import (
"fmt"
"sort"
"sync"
"github.com/pkg/errors"
)
// CompressionAlgorithm represents the compression algorithms as described in https://tools.ietf.org/html/rfc7518#section-7.3
type CompressionAlgorithm string
// Supported values for CompressionAlgorithm
const (
Deflate CompressionAlgorithm = "DEF" // DEFLATE (RFC 1951)
NoCompress CompressionAlgorithm = "" // No compression
)
var allCompressionAlgorithms = map[CompressionAlgorithm]struct{}{
Deflate: {},
NoCompress: {},
}
var listCompressionAlgorithmOnce sync.Once
var listCompressionAlgorithm []CompressionAlgorithm
// CompressionAlgorithms returns a list of all available values for CompressionAlgorithm
func CompressionAlgorithms() []CompressionAlgorithm {
listCompressionAlgorithmOnce.Do(func() {
listCompressionAlgorithm = make([]CompressionAlgorithm, 0, len(allCompressionAlgorithms))
for v := range allCompressionAlgorithms {
listCompressionAlgorithm = append(listCompressionAlgorithm, v)
}
sort.Slice(listCompressionAlgorithm, func(i, j int) bool {
return string(listCompressionAlgorithm[i]) < string(listCompressionAlgorithm[j])
})
})
return listCompressionAlgorithm
}
// Accept is used when conversion from values given by
// outside sources (such as JSON payloads) is required
func (v *CompressionAlgorithm) Accept(value interface{}) error {
var tmp CompressionAlgorithm
if x, ok := value.(CompressionAlgorithm); ok {
tmp = x
} else {
var s string
switch x := value.(type) {
case fmt.Stringer:
s = x.String()
case string:
s = x
default:
return errors.Errorf(`invalid type for jwa.CompressionAlgorithm: %T`, value)
}
tmp = CompressionAlgorithm(s)
}
if _, ok := allCompressionAlgorithms[tmp]; !ok {
return errors.Errorf(`invalid jwa.CompressionAlgorithm value`)
}
*v = tmp
return nil
}
// String returns the string representation of a CompressionAlgorithm
func (v CompressionAlgorithm) String() string {
return string(v)
}