Documentation
¶
Overview ¶
Package multipartbuilder provides simple streaming multipart builder.
Usage:
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
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a multipart builder. It is not thread-safe.
func (*Builder) Build ¶
func (b *Builder) Build() (string, io.ReadCloser)
Build finalizes Builder, returning Content-Type and multipart reader. It should be called only once for Builder. Returned reader should be used (Read/Close) at least once to clean up properly. Any errors are bound to returned reader (will be returned on Read/Close).
Click to show internal directories.
Click to hide internal directories.