package rc import ( "embed" _ "embed" "path" "strings" "go.stargrave.org/godlighty" ) const MIMEDir = "mime" var ( //go:embed mime mimes embed.FS CompressibleMIMEBundles = map[string]struct{}{ "mail": struct{}{}, "playlist": struct{}{}, "subtitle": struct{}{}, "text": struct{}{}, "web": struct{}{}, "xml": struct{}{}, } CompressibleMIMEExts = []string{ ".dvi", ".eps", ".fb2", ".meta4", ".metalink", ".ps", } ) func parseMIME(p string) map[string]string { tsv, err := mimes.ReadFile(path.Join(MIMEDir, p)) if err != nil { panic(err) } m := make(map[string]string) for _, line := range strings.Split(string(tsv), "\n") { if len(line) == 0 || line[0] == '#' { continue } cols := strings.SplitN(line, "\t", 2) m[cols[0]] = cols[1] } return m } func init() { entries, err := mimes.ReadDir(MIMEDir) if err != nil { panic(err) } for _, entry := range entries { bundle := entry.Name() _, allCompressible := CompressibleMIMEBundles[bundle] for ext, mediaType := range parseMIME(bundle) { godlighty.ContentTypes[ext] = mediaType if allCompressible { godlighty.CompressibleContentTypes[mediaType] = struct{}{} } } } CompressibleMIMEBundles = nil for _, ext := range CompressibleMIMEExts { mediaType := godlighty.ContentTypes[ext] godlighty.CompressibleContentTypes[mediaType] = struct{}{} } CompressibleMIMEExts = nil }