Source file src/net/textproto/example_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package textproto_test
     6  
     7  import (
     8  	"bufio"
     9  	"fmt"
    10  	"net/textproto"
    11  	"strings"
    12  )
    13  
    14  func ExampleReader_ReadMIMEHeader() {
    15  	input := "content-type: text/plain\r\n" +
    16  		"x-tag: one\r\n" +
    17  		"x-tag: two\r\n" +
    18  		"long-key: Even\r\n" +
    19  		"\tLonger Value\r\n\r\n"
    20  	r := textproto.NewReader(bufio.NewReader(strings.NewReader(input)))
    21  
    22  	header, err := r.ReadMIMEHeader()
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  	fmt.Println(header["Content-Type"][0])
    27  	fmt.Println(header["X-Tag"])
    28  	fmt.Println(header["Long-Key"])
    29  
    30  	// Output:
    31  	// text/plain
    32  	// [one two]
    33  	// [Even Longer Value]
    34  }
    35  

View as plain text