mime.go 504 B

12345678910111213141516
  1. package mime
  2. import "strings"
  3. // Split spits the mimetype into its main type and subtype.
  4. func Split(mimeTypeFull string) (mimeType, mimeSubType string) {
  5. // Replace with strings.Cut() when Go 1.18 is our new base version.
  6. separatorIndex := strings.IndexByte(mimeTypeFull, '/')
  7. if separatorIndex == -1 || mimeTypeFull[separatorIndex+1:] == "" {
  8. return "", "" // Empty or only one part. Ignore.
  9. }
  10. mimeType = mimeTypeFull[:separatorIndex]
  11. mimeSubType = mimeTypeFull[separatorIndex+1:]
  12. return
  13. }