Skip to content

Simple streaming multipart builder for Go (Golang)

License

Notifications You must be signed in to change notification settings

mxmCherry/multipartbuilder

Repository files navigation

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
}

About

Simple streaming multipart builder for Go (Golang)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages