-
Notifications
You must be signed in to change notification settings - Fork 6
/
media_type.go
37 lines (31 loc) · 1.01 KB
/
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
34
35
36
37
// Copyright 2019 Communication Service/Software Laboratory, National Chiao Tung University (free5gc.org)
//
// SPDX-License-Identifier: Apache-2.0
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
}