Standard library / mime/multipart

multipart.Writer.Close()

Write the closing delimiter. Check its error, since writing data alone does not finish a valid multipart body. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) Close() error

Return Value

error

Nil on success, otherwise the operation error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "mime/multipart"  "strings")
func main() {  var b bytes.Buffer  w := multipart.NewWriter(&b)  check(w.SetBoundary("demo"))  check(w.WriteField("name", "Ada"))  check(w.Close())  fmt.Println(strings.HasSuffix(b.String(), "\r\n--demo--\r\n"))}
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