summaryrefslogtreecommitdiff
path: root/devdocs/go/mime%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/go/mime%2Findex.html')
-rw-r--r--devdocs/go/mime%2Findex.html153
1 files changed, 153 insertions, 0 deletions
diff --git a/devdocs/go/mime%2Findex.html b/devdocs/go/mime%2Findex.html
new file mode 100644
index 00000000..aa865152
--- /dev/null
+++ b/devdocs/go/mime%2Findex.html
@@ -0,0 +1,153 @@
+<h1> Package mime </h1> <ul id="short-nav">
+<li><code>import "mime"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+<li><a href="#pkg-subdirectories">Subdirectories</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package mime implements parts of the MIME spec. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#pkg-constants">Constants</a></li>
+<li><a href="#pkg-variables">Variables</a></li>
+<li><a href="#AddExtensionType">func AddExtensionType(ext, typ string) error</a></li>
+<li><a href="#ExtensionsByType">func ExtensionsByType(typ string) ([]string, error)</a></li>
+<li><a href="#FormatMediaType">func FormatMediaType(t string, param map[string]string) string</a></li>
+<li><a href="#ParseMediaType">func ParseMediaType(v string) (mediatype string, params map[string]string, err error)</a></li>
+<li><a href="#TypeByExtension">func TypeByExtension(ext string) string</a></li>
+<li><a href="#WordDecoder">type WordDecoder</a></li>
+<li> <a href="#WordDecoder.Decode">func (d *WordDecoder) Decode(word string) (string, error)</a>
+</li>
+<li> <a href="#WordDecoder.DecodeHeader">func (d *WordDecoder) DecodeHeader(header string) (string, error)</a>
+</li>
+<li><a href="#WordEncoder">type WordEncoder</a></li>
+<li> <a href="#WordEncoder.Encode">func (e WordEncoder) Encode(charset, s string) string</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_FormatMediaType">FormatMediaType</a></dd> <dd><a class="exampleLink" href="#example_ParseMediaType">ParseMediaType</a></dd> <dd><a class="exampleLink" href="#example_WordDecoder_Decode">WordDecoder.Decode</a></dd> <dd><a class="exampleLink" href="#example_WordDecoder_DecodeHeader">WordDecoder.DecodeHeader</a></dd> <dd><a class="exampleLink" href="#example_WordEncoder_Encode">WordEncoder.Encode</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>encodedword.go</span> <span>grammar.go</span> <span>mediatype.go</span> <span>type.go</span> <span>type_unix.go</span> </p> <h2 id="pkg-constants">Constants</h2> <pre data-language="go">const (
+ // BEncoding represents Base64 encoding scheme as defined by RFC 2045.
+ BEncoding = WordEncoder('b')
+ // QEncoding represents the Q-encoding scheme as defined by RFC 2047.
+ QEncoding = WordEncoder('q')
+)</pre> <h2 id="pkg-variables">Variables</h2> <p>ErrInvalidMediaParameter is returned by ParseMediaType if the media type value was found but there was an error parsing the optional parameters </p>
+<pre data-language="go">var ErrInvalidMediaParameter = errors.New("mime: invalid media parameter")</pre> <h2 id="AddExtensionType">func <span>AddExtensionType</span> </h2> <pre data-language="go">func AddExtensionType(ext, typ string) error</pre> <p>AddExtensionType sets the MIME type associated with the extension ext to typ. The extension should begin with a leading dot, as in ".html". </p>
+<h2 id="ExtensionsByType">func <span>ExtensionsByType</span> <span title="Added in Go 1.5">1.5</span> </h2> <pre data-language="go">func ExtensionsByType(typ string) ([]string, error)</pre> <p>ExtensionsByType returns the extensions known to be associated with the MIME type typ. The returned extensions will each begin with a leading dot, as in ".html". When typ has no associated extensions, ExtensionsByType returns an nil slice. </p>
+<h2 id="FormatMediaType">func <span>FormatMediaType</span> </h2> <pre data-language="go">func FormatMediaType(t string, param map[string]string) string</pre> <p>FormatMediaType serializes mediatype t and the parameters param as a media type conforming to RFC 2045 and RFC 2616. The type and parameter names are written in lower-case. When any of the arguments result in a standard violation then FormatMediaType returns the empty string. </p> <h4 id="example_FormatMediaType"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">mediatype := "text/html"
+params := map[string]string{
+ "charset": "utf-8",
+}
+
+result := mime.FormatMediaType(mediatype, params)
+
+fmt.Println("result:", result)
+</pre> <p>Output:</p> <pre class="output" data-language="go">result: text/html; charset=utf-8
+</pre> <h2 id="ParseMediaType">func <span>ParseMediaType</span> </h2> <pre data-language="go">func ParseMediaType(v string) (mediatype string, params map[string]string, err error)</pre> <p>ParseMediaType parses a media type value and any optional parameters, per RFC 1521. Media types are the values in Content-Type and Content-Disposition headers (RFC 2183). On success, ParseMediaType returns the media type converted to lowercase and trimmed of white space and a non-nil map. If there is an error parsing the optional parameter, the media type will be returned along with the error ErrInvalidMediaParameter. The returned map, params, maps from the lowercase attribute to the attribute value with its case preserved. </p> <h4 id="example_ParseMediaType"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">mediatype, params, err := mime.ParseMediaType("text/html; charset=utf-8")
+if err != nil {
+ panic(err)
+}
+
+fmt.Println("type:", mediatype)
+fmt.Println("charset:", params["charset"])
+</pre> <p>Output:</p> <pre class="output" data-language="go">type: text/html
+charset: utf-8
+</pre> <h2 id="TypeByExtension">func <span>TypeByExtension</span> </h2> <pre data-language="go">func TypeByExtension(ext string) string</pre> <p>TypeByExtension returns the MIME type associated with the file extension ext. The extension ext should begin with a leading dot, as in ".html". When ext has no associated type, TypeByExtension returns "". </p>
+<p>Extensions are looked up first case-sensitively, then case-insensitively. </p>
+<p>The built-in table is small but on unix it is augmented by the local system's MIME-info database or mime.types file(s) if available under one or more of these names: </p>
+<pre data-language="go">/usr/local/share/mime/globs2
+/usr/share/mime/globs2
+/etc/mime.types
+/etc/apache2/mime.types
+/etc/apache/mime.types
+</pre> <p>On Windows, MIME types are extracted from the registry. </p>
+<p>Text types have the charset parameter set to "utf-8" by default. </p>
+<h2 id="WordDecoder">type <span>WordDecoder</span> <span title="Added in Go 1.5">1.5</span> </h2> <p>A WordDecoder decodes MIME headers containing RFC 2047 encoded-words. </p>
+<pre data-language="go">type WordDecoder struct {
+ // CharsetReader, if non-nil, defines a function to generate
+ // charset-conversion readers, converting from the provided
+ // charset into UTF-8.
+ // Charsets are always lower-case. utf-8, iso-8859-1 and us-ascii charsets
+ // are handled by default.
+ // One of the CharsetReader's result values must be non-nil.
+ CharsetReader func(charset string, input io.Reader) (io.Reader, error)
+}
+</pre> <h3 id="WordDecoder.Decode">func (*WordDecoder) <span>Decode</span> <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func (d *WordDecoder) Decode(word string) (string, error)</pre> <p>Decode decodes an RFC 2047 encoded-word. </p> <h4 id="example_WordDecoder_Decode"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">dec := new(mime.WordDecoder)
+header, err := dec.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
+if err != nil {
+ panic(err)
+}
+fmt.Println(header)
+
+dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
+ switch charset {
+ case "x-case":
+ // Fake character set for example.
+ // Real use would integrate with packages such
+ // as code.google.com/p/go-charset
+ content, err := io.ReadAll(input)
+ if err != nil {
+ return nil, err
+ }
+ return bytes.NewReader(bytes.ToUpper(content)), nil
+ default:
+ return nil, fmt.Errorf("unhandled charset %q", charset)
+ }
+}
+header, err = dec.Decode("=?x-case?q?hello!?=")
+if err != nil {
+ panic(err)
+}
+fmt.Println(header)
+</pre> <p>Output:</p> <pre class="output" data-language="go">¡Hola, señor!
+HELLO!
+</pre> <h3 id="WordDecoder.DecodeHeader">func (*WordDecoder) <span>DecodeHeader</span> <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func (d *WordDecoder) DecodeHeader(header string) (string, error)</pre> <p>DecodeHeader decodes all encoded-words of the given string. It returns an error if and only if CharsetReader of d returns an error. </p> <h4 id="example_WordDecoder_DecodeHeader"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">dec := new(mime.WordDecoder)
+header, err := dec.DecodeHeader("=?utf-8?q?=C3=89ric?= &lt;eric@example.org&gt;, =?utf-8?q?Ana=C3=AFs?= &lt;anais@example.org&gt;")
+if err != nil {
+ panic(err)
+}
+fmt.Println(header)
+
+header, err = dec.DecodeHeader("=?utf-8?q?=C2=A1Hola,?= =?utf-8?q?_se=C3=B1or!?=")
+if err != nil {
+ panic(err)
+}
+fmt.Println(header)
+
+dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
+ switch charset {
+ case "x-case":
+ // Fake character set for example.
+ // Real use would integrate with packages such
+ // as code.google.com/p/go-charset
+ content, err := io.ReadAll(input)
+ if err != nil {
+ return nil, err
+ }
+ return bytes.NewReader(bytes.ToUpper(content)), nil
+ default:
+ return nil, fmt.Errorf("unhandled charset %q", charset)
+ }
+}
+header, err = dec.DecodeHeader("=?x-case?q?hello_?= =?x-case?q?world!?=")
+if err != nil {
+ panic(err)
+}
+fmt.Println(header)
+</pre> <p>Output:</p> <pre class="output" data-language="go">Éric &lt;eric@example.org&gt;, Anaïs &lt;anais@example.org&gt;
+¡Hola, señor!
+HELLO WORLD!
+</pre> <h2 id="WordEncoder">type <span>WordEncoder</span> <span title="Added in Go 1.5">1.5</span> </h2> <p>A WordEncoder is an RFC 2047 encoded-word encoder. </p>
+<pre data-language="go">type WordEncoder byte</pre> <h3 id="WordEncoder.Encode">func (WordEncoder) <span>Encode</span> <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func (e WordEncoder) Encode(charset, s string) string</pre> <p>Encode returns the encoded-word form of s. If s is ASCII without special characters, it is returned unchanged. The provided charset is the IANA charset name of s. It is case insensitive. </p> <h4 id="example_WordEncoder_Encode"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">fmt.Println(mime.QEncoding.Encode("utf-8", "¡Hola, señor!"))
+fmt.Println(mime.QEncoding.Encode("utf-8", "Hello!"))
+fmt.Println(mime.BEncoding.Encode("UTF-8", "¡Hola, señor!"))
+fmt.Println(mime.QEncoding.Encode("ISO-8859-1", "Caf\xE9"))
+</pre> <p>Output:</p> <pre class="output" data-language="go">=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=
+Hello!
+=?UTF-8?b?wqFIb2xhLCBzZcOxb3Ih?=
+=?ISO-8859-1?q?Caf=E9?=
+</pre> <h2 id="pkg-subdirectories">Subdirectories</h2> <div class="pkg-dir"> <table> <tr> <th class="pkg-name">Name</th> <th class="pkg-synopsis">Synopsis</th> </tr> <tr> <td colspan="2"><a href="../index">..</a></td> </tr> <tr> <td class="pkg-name"> <a href="multipart/index">multipart</a> </td> <td class="pkg-synopsis"> Package multipart implements MIME multipart parsing, as defined in RFC 2046. </td> </tr> <tr> <td class="pkg-name"> <a href="quotedprintable/index">quotedprintable</a> </td> <td class="pkg-synopsis"> Package quotedprintable implements quoted-printable encoding as specified by RFC 2045. </td> </tr> </table> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/mime/" class="_attribution-link">http://golang.org/pkg/mime/</a>
+ </p>
+</div>