Personal Git forge.
package mimeimport ( "encoding/base64" "fmt" "html/template" "net/http" "strings")// these are mostly helper functions for the templating engine, perhaps.// wrapper but at least I'll be able to change it in the future if something goes southfunc Type(data []byte) string { return http.DetectContentType(data)}// returns true if the mimetype is an image (SVG ALSO COUNTS)func IsImage(mime string) bool { return strings.HasPrefix(mime, "image/")}// returns true if the mimetype is a videofunc IsVideo(mime string) bool { return strings.HasPrefix(mime, "video/")}// returns true if the mimetype is text (or code, possibly)func IsText(mime string) bool { return strings.HasPrefix(mime, "text/")}// generates one of those `data:text/javascript;base64,gibberish-here`func DataURI(data []byte, mime string) string { encoded := base64.StdEncoding.EncodeToString(data) return fmt.Sprintf("data:%s;base64,%s", mime, encoded)}// makes it not auto-escape when used before a "src="func Src(data []byte, mime string) template.URL { return template.URL(DataURI(data, mime))}func ToStr(data []byte) string { return string(data)}