github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/iohelpers/mimetypes.go (about) 1 package iohelpers 2 3 import ( 4 "mime" 5 ) 6 7 const ( 8 TextMimetype = "text/plain" 9 CSVMimetype = "text/csv" 10 JSONMimetype = "application/json" 11 JSONArrayMimetype = "application/array+json" 12 TOMLMimetype = "application/toml" 13 YAMLMimetype = "application/yaml" 14 EnvMimetype = "application/x-env" 15 CUEMimetype = "application/cue" 16 ) 17 18 // mimeTypeAliases defines a mapping for non-canonical mime types that are 19 // sometimes seen in the wild 20 var mimeTypeAliases = map[string]string{ 21 "application/x-yaml": YAMLMimetype, 22 "application/text": TextMimetype, 23 } 24 25 func MimeAlias(m string) string { 26 // normalize the type by removing any extra parameters 27 m, _, _ = mime.ParseMediaType(m) 28 29 if a, ok := mimeTypeAliases[m]; ok { 30 return a 31 } 32 return m 33 }