-
Notifications
You must be signed in to change notification settings - Fork 3
/
contentType.go
39 lines (33 loc) · 1.12 KB
/
contentType.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
package viperKit
import (
"github.com/richelieu-yang/chimera/v3/src/core/sliceKit"
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"github.com/richelieu-yang/chimera/v3/src/file/fileKit"
"github.com/spf13/viper"
)
// IsContentTypeSupported
/*
@param extName "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"
*/
func IsContentTypeSupported(contentType string) bool {
return sliceKit.Contains(viper.SupportedExts, contentType)
}
// PolyfillContentType
/*
e.g.
extname := ".JSON"
fmt.Println(viperKit.PolyfillContentType(extname)) // "json"
@param extName "json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"
*/
func PolyfillContentType(contentType string) string {
contentType = strKit.TrimSpace(contentType)
contentType = strKit.ToLower(contentType)
if len(contentType) > 1 && strKit.StartWith(contentType, ".") {
contentType = strKit.RemovePrefixIfExists(contentType, ".")
}
return contentType
}
func GetContentType(path string) string {
contentType := fileKit.GetExtName(path)
return PolyfillContentType(contentType)
}