-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize_format.go
67 lines (56 loc) · 1.85 KB
/
serialize_format.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
package main
import (
"slices"
"strings"
)
type SerializeFormat string
const (
SerializeFormatUnknown SerializeFormat = ""
SerializeFormatXml SerializeFormat = "xml"
SerializeFormatJson SerializeFormat = "json"
SerializeFormatFhirXml SerializeFormat = "fhir+xml"
SerializeFormatFhirJson SerializeFormat = "fhir+json"
SerializeFormatFhirXmlLegacy SerializeFormat = "xml+fhir"
SerializeFormatFhirJsonLegacy SerializeFormat = "json+fhir"
SerializeFormatFhirXmlPatch SerializeFormat = "xml-patch+xml"
SerializeFormatFhirJsonPatch SerializeFormat = "json-patch+json"
)
var (
serializeFormats = []SerializeFormat{
SerializeFormatXml,
SerializeFormatJson,
SerializeFormatFhirXml,
SerializeFormatFhirJson,
SerializeFormatFhirXmlLegacy,
SerializeFormatFhirJsonLegacy,
SerializeFormatFhirXmlPatch,
SerializeFormatFhirJsonPatch,
}
)
func (sf SerializeFormat) Valid() bool {
return slices.Contains(serializeFormats, sf)
}
func (sf SerializeFormat) IsFHIR() bool {
return strings.Contains(string(sf), "fhir") ||
sf == SerializeFormatFhirXmlPatch ||
sf == SerializeFormatFhirJsonPatch
}
func (sf SerializeFormat) IsFHIRLegacy() bool {
return sf == SerializeFormatFhirXmlPatch || sf == SerializeFormatFhirJsonLegacy
}
func (sf SerializeFormat) IsFHIRPatch() bool {
return sf == SerializeFormatFhirXmlPatch || sf == SerializeFormatFhirJsonPatch
}
func (sf SerializeFormat) IsXml() bool {
return sf == SerializeFormatXml || sf == SerializeFormatFhirXml || sf == SerializeFormatFhirXmlLegacy
}
func (sf SerializeFormat) IsJson() bool {
return sf == SerializeFormatJson || sf == SerializeFormatFhirJson || sf == SerializeFormatFhirJsonLegacy
}
func serializeFormatStrings() []string {
out := make([]string, len(serializeFormats))
for i := range serializeFormats {
out[i] = string(serializeFormats[i])
}
return out
}