forked from free5gc/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_type.go
33 lines (28 loc) · 862 Bytes
/
media_type.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
package openapi
import "regexp"
// MediaKind - represents the sets of media type
type MediaKind int
// MediaKind enums
const (
MediaKindUnsupported MediaKind = iota
MediaKindPlaintext MediaKind = iota
MediaKindJSON
MediaKindXML
MediaKindMultipartRelated
)
var (
jsonRegex = regexp.MustCompile(`(?i:(?:application|text)/(?:[a-zA-Z0-9./-]+\+)?json)`)
xmlRegex = regexp.MustCompile(`(?i:(?:application|text)/xml)`)
multipartRelatedRegex = regexp.MustCompile("(?i:multipart/related)")
)
// KindOfMediaType - returns Mediakind of the media type
func KindOfMediaType(mediaType string) MediaKind {
if jsonRegex.MatchString(mediaType) {
return MediaKindJSON
} else if xmlRegex.MatchString(mediaType) {
return MediaKindXML
} else if multipartRelatedRegex.MatchString(mediaType) {
return MediaKindMultipartRelated
}
return MediaKindUnsupported
}