Standard library / mime/multipart

multipart.NewWriter()

Create a multipart writer with a random boundary. Close it to emit the terminating boundary; use FormDataContentType for the matching HTTP header. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func NewWriter(w io.Writer) *Writer

Parameters & Attributes

NameTypeDescription
wio.WriterUnderlying destination stream.

Return Value

*Writer

Writer wrapping the destination.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "mime/multipart")
func main() {  var b bytes.Buffer  w := multipart.NewWriter(&b)  fmt.Println(len(w.Boundary()) > 0)  check(w.Close())}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference