Skip to content

Commit f4f314b

Browse files
authored
Merge pull request #12 from mazrean/doc/godoc
write godoc
2 parents 3216ba1 + 9fab9ee commit f4f314b

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

formstream.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,32 @@ const (
5757
defaultMaxMemFileSize = 32 * MB
5858
)
5959

60+
// WithMaxParts sets the maximum number of parts to be parsed.
61+
// default: 10000
6062
func WithMaxParts(maxParts uint) ParserOption {
6163
return func(c *parserConfig) {
6264
c.maxParts = maxParts
6365
}
6466
}
6567

68+
// WithMaxHeaders sets the maximum number of headers to be parsed.
69+
// default: 10000
6670
func WithMaxHeaders(maxHeaders uint) ParserOption {
6771
return func(c *parserConfig) {
6872
c.maxHeaders = maxHeaders
6973
}
7074
}
7175

76+
// WithMaxMemSize sets the maximum memory size to be used for parsing.
77+
// default: 32MB
7278
func WithMaxMemSize(maxMemSize DataSize) ParserOption {
7379
return func(c *parserConfig) {
7480
c.maxMemSize = maxMemSize
7581
}
7682
}
7783

84+
// WithMaxMemFileSize sets the maximum memory size to be used for parsing a file.
85+
// default: 32MB
7886
func WithMaxMemFileSize(maxMemFileSize DataSize) ParserOption {
7987
return func(c *parserConfig) {
8088
c.maxMemFileSize = maxMemFileSize
@@ -86,10 +94,12 @@ type Value struct {
8694
header Header
8795
}
8896

97+
// Unwrap returns the content and header of the value.
8998
func (v Value) Unwrap() (string, Header) {
9099
return string(v.content), v.header
91100
}
92101

102+
// UnwrapRaw returns the raw content and header of the value.
93103
func (v Value) UnwrapRaw() ([]byte, Header) {
94104
return v.content, v.header
95105
}
@@ -112,18 +122,26 @@ func newHeader(h textproto.MIMEHeader) Header {
112122
}
113123
}
114124

125+
// Get returns the first value associated with the given key.
126+
// If there are no values associated with the key, Get returns "".
115127
func (h Header) Get(key string) string {
116128
return h.header.Get(key)
117129
}
118130

131+
// ContentType returns the value of the "Content-Type" header field.
132+
// If there are no values associated with the key, ContentType returns "".
119133
func (h Header) ContentType() string {
120134
return h.header.Get("Content-Type")
121135
}
122136

137+
// Name returns the value of the "name" parameter in the "Content-Disposition" header field.
138+
// If there are no values associated with the key, Name returns "".
123139
func (h Header) Name() string {
124140
return h.dispositionParams["name"]
125141
}
126142

143+
// FileName returns the value of the "filename" parameter in the "Content-Disposition" header field.
144+
// If there are no values associated with the key, FileName returns "".
127145
func (h Header) FileName() string {
128146
return h.dispositionParams["filename"]
129147
}

formstream_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ func createSampleForm(w io.Writer, fileSize formstream.DataSize, boundary string
118118
if err != nil {
119119
return fmt.Errorf("failed to create part: %w", err)
120120
}
121+
122+
mbData := make([]byte, formstream.MB)
121123
for i := 0; i < int(fileSize/formstream.MB); i++ {
122-
_, err := pw.Write([]byte(strings.Repeat("a", int(formstream.MB))))
124+
_, err := pw.Write(mbData)
123125
if err != nil {
124126
return fmt.Errorf("failed to write: %w", err)
125127
}

parse.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
ErrTooLargeForm = errors.New("too large form")
2222
)
2323

24+
// Parse parses the multipart form from r.
2425
func (p *Parser) Parse(r io.Reader) (err error) {
2526
hsc := newHookSatisfactionChecker(p.hookMap, &p.parserConfig)
2627
defer func() {

register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
)
66

7+
// Register registers a stream hook with the given name.
78
func (p *Parser) Register(name string, fn StreamHookFunc, options ...RegisterOption) error {
89
if _, ok := p.hookMap[name]; ok {
910
return DuplicateHookNameError{Name: name}
@@ -36,6 +37,7 @@ type registerConfig struct {
3637

3738
type RegisterOption func(*registerConfig)
3839

40+
// WithRequiredPart sets the required part names for the stream hook.
3941
func WithRequiredPart(name string) RegisterOption {
4042
return func(c *registerConfig) {
4143
c.requireParts = append(c.requireParts, name)

0 commit comments

Comments
 (0)