Documentation
¶
Index ¶
- Variables
- type DataSize
- type DuplicateHookNameError
- type Header
- type Parser
- func (p *Parser) Parse(r io.Reader) (err error)
- func (p *Parser) Register(name string, fn StreamHookFunc, options ...RegisterOption) error
- func (p *Parser) Value(key string) (string, Header, bool)
- func (p *Parser) ValueMap() map[string][]Value
- func (p *Parser) ValueRaw(key string) ([]byte, Header, bool)
- func (p *Parser) Values(key string) ([]Value, bool)
- type ParserOption
- type RegisterOption
- type StreamHookFunc
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooManyParts is returned when the parts are more than MaxParts. ErrTooManyParts = errors.New("too many parts") // ErrTooManyHeaders is returned when the headers are more than MaxHeaders. ErrTooManyHeaders = errors.New("too many headers") // ErrTooLargeForm is returned when the form is too large for the parser to handle within the memory limit. ErrTooLargeForm = errors.New("too large form") )
Functions ¶
This section is empty.
Types ¶
type DuplicateHookNameError ¶
type DuplicateHookNameError struct {
Name string
}
func (DuplicateHookNameError) Error ¶
func (e DuplicateHookNameError) Error() string
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
func (Header) ContentType ¶
ContentType returns the value of the "Content-Type" header field. If there are no values associated with the key, ContentType returns "".
func (Header) FileName ¶
FileName returns the value of the "filename" parameter in the "Content-Disposition" header field. If there are no values associated with the key, FileName returns "".
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewParser ¶
func NewParser(boundary string, options ...ParserOption) *Parser
Example ¶
buf := strings.NewReader(`
--boundary
Content-Disposition: form-data; name="field"
value
--boundary
Content-Disposition: form-data; name="stream"; filename="file.txt"
Content-Type: text/plain
large file contents
--boundary--`)
parser := formstream.NewParser("boundary")
err := parser.Register("stream", func(r io.Reader, header formstream.Header) error {
fmt.Println("---stream---")
fmt.Printf("file name: %s\n", header.FileName())
fmt.Printf("Content-Type: %s\n", header.ContentType())
fmt.Println()
_, err := io.Copy(os.Stdout, r)
if err != nil {
return fmt.Errorf("failed to copy: %w", err)
}
return nil
}, formstream.WithRequiredPart("field"))
if err != nil {
log.Fatal(err)
}
err = parser.Parse(buf)
if err != nil {
log.Fatal(err)
}
fmt.Printf("\n\n")
fmt.Println("---field---")
content, _, _ := parser.Value("field")
fmt.Println(content)
Output: ---stream--- file name: file.txt Content-Type: text/plain large file contents ---field--- value
func (*Parser) Register ¶
func (p *Parser) Register(name string, fn StreamHookFunc, options ...RegisterOption) error
Register registers a stream hook with the given name.
type ParserOption ¶
type ParserOption func(*parserConfig)
func WithMaxHeaders ¶
func WithMaxHeaders(maxHeaders uint) ParserOption
WithMaxHeaders sets the maximum number of headers to be parsed. default: 10000
func WithMaxMemFileSize ¶
func WithMaxMemFileSize(maxMemFileSize DataSize) ParserOption
WithMaxMemFileSize sets the maximum memory size to be used for parsing a file. default: 32MB
func WithMaxMemSize ¶
func WithMaxMemSize(maxMemSize DataSize) ParserOption
WithMaxMemSize sets the maximum memory size to be used for parsing. default: 32MB
func WithMaxParts ¶
func WithMaxParts(maxParts uint) ParserOption
WithMaxParts sets the maximum number of parts to be parsed. default: 10000
type RegisterOption ¶
type RegisterOption func(*registerConfig)
func WithRequiredPart ¶
func WithRequiredPart(name string) RegisterOption
WithRequiredPart sets the required part names for the stream hook.
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
http-upload
command
|
|
|
internal
|
|
|
condition_judge/mock
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
