Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.3 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.3 KB

multipartbuilder

Go Reference Go Test Go Report Card

Simple streaming multipart builder for Go (Golang).

Usage

go get -u github.com/mxmCherry/multipartbuilder
import "github.com/mxmCherry/multipartbuilder"
builder := multipartbuilder.New()
builder.AddField("field", "value")

// or use chaining:
builder.
	AddReader("reader", strings.NewReader("Some reader")).
	AddFile("file", "path/to/file.bin")

// finalize builder (it should not be used anymore after this);
// any errors will be returned on bodyReader usage (Read/Close):
contentType, bodyReader := builder.Build()

// for proper cleanup, returned bodyReader should be used at least once,
// so at least close it (multiple closes are fine):
defer bodyReader.Close()

// finally, use built reader:
resp, err := http.Post("https://test.com/", contentType, bodyReader)
if err != nil {
	// handle error
}