github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/data/mimetypes.go (about)

     1  package data
     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  }