Golang mime/multipart.SetBoundary() function example

package mime/multipart

Golang mime/multipart.SetBoundary() function usage example

 var b bytes.Buffer
 w := NewWriter(&b)

 err := w.SetBoundary(strings.Repeat("x", 69))

 if err != nil {
 panic(err)
 }

By default, the boundary are set by this function

 func randomBoundary() string {
 var buf [30]byte
 _, err := io.ReadFull(rand.Reader, buf[:])
 if err != nil {
 panic(err)
 }
 return fmt.Sprintf("%x", buf[:])
 }

but you can generate the boundary by your own, then you get the header for CreatePart, call NewWriter, and set the boundary by calling multipart.Writer.SetBoundary.

Reference :

http://golang.org/pkg/mime/multipart/#Writer.SetBoundary

Advertisement