github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/resource/api/mime.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 //+build go1.6 5 6 package api 7 8 import "mime" 9 10 // TODO(natefinch) remove this once we support building on go 1.6 for all platforms. 11 12 // formatMediaType serializes mediatype t and the parameters 13 // param as a media type conforming to RFC 2045 and RFC 2616. 14 // The type and parameter names are written in lower-case. 15 // When any of the arguments result in a standard violation then 16 // formatMediaType returns the empty string. 17 func formatMediaType(t string, param map[string]string) string { 18 return mime.FormatMediaType(t, param) 19 } 20 21 // parseMediaType parses a media type value and any optional 22 // parameters, per RFC 1521. Media types are the values in 23 // Content-Type and Content-Disposition headers (RFC 2183). 24 // On success, parseMediaType returns the media type converted 25 // to lowercase and trimmed of white space and a non-nil map. 26 // The returned map, params, maps from the lowercase 27 // attribute to the attribute value with its case preserved. 28 func parseMediaType(v string) (mediatype string, params map[string]string, err error) { 29 return mime.ParseMediaType(v) 30 } 31 32 func getEncoder() encoder { 33 return mime.BEncoding 34 } 35 36 func getDecoder() decoder { 37 return &mime.WordDecoder{} 38 }