Standard library / mime/multipart

multipart.Writer.SetBoundary()

Set an explicit valid boundary before creating parts. Length is 1–70 bytes and allowed characters are restricted. Expected stdout: 'true\ndemo\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) SetBoundary(boundary string) error

Parameters & Attributes

NameTypeDescription
boundarystringMultipart delimiter, without the leading two hyphens.

Return Value

error

Nil on success, otherwise the operation error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "mime/multipart")
func main() {  var b bytes.Buffer  w := multipart.NewWriter(&b)  fmt.Println(w.SetBoundary("") != nil)  check(w.SetBoundary("demo"))  fmt.Println(w.Boundary())  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