https://github.com/mxmCherry/multipartbuilder
Simple streaming multipart builder for Go (Golang)
https://github.com/mxmCherry/multipartbuilder
builder go golang multipart
Last synced: 30 days ago
JSON representation
Simple streaming multipart builder for Go (Golang)
- Host: GitHub
- URL: https://github.com/mxmCherry/multipartbuilder
- Owner: mxmCherry
- License: unlicense
- Created: 2017-02-19T17:11:58.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-08-04T14:58:58.000Z (10 months ago)
- Last Synced: 2024-09-26T09:39:51.654Z (8 months ago)
- Topics: builder, go, golang, multipart
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multipartbuilder
[](https://pkg.go.dev/github.com/mxmCherry/multipartbuilder)
[](https://github.com/mxmCherry/multipartbuilder/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/mxmCherry/multipartbuilder)Simple streaming multipart builder for Go (Golang).
# Usage
```bash
go get -u github.com/mxmCherry/multipartbuilder
``````go
import "github.com/mxmCherry/multipartbuilder"
``````go
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
}
```