diff --git a/internal/multipart/component.go b/internal/multipart/component.go index df4d8bf..0080bd2 100644 --- a/internal/multipart/component.go +++ b/internal/multipart/component.go @@ -13,19 +13,19 @@ func (comp *Component) parseHeaders(_raw []byte) error { // 1. Extract lines _lines := strings.Split(string(_raw), "\n") if len(_lines) < 2 { - return ErrNoHeader + return errNoHeader } // 2. trim each line + remove 'Content-Disposition' prefix header := strings.Trim(_lines[0], " \t\r") if !strings.HasPrefix(header, "Content-Disposition: form-data;") { - return ErrNoHeader + return errNoHeader } header = strings.Trim(header[len("Content-Disposition: form-data;"):], " \t\r") if len(header) < 1 { - return ErrNoHeader + return errNoHeader } // 3. Extract each key-value pair diff --git a/internal/multipart/types.go b/internal/multipart/multipart.go similarity index 52% rename from internal/multipart/types.go rename to internal/multipart/multipart.go index a14fd61..970cca8 100644 --- a/internal/multipart/types.go +++ b/internal/multipart/multipart.go @@ -3,19 +3,18 @@ package multipart // cerr allows you to create constant "const" error with type boxing. type cerr string -// Error implements the error builtin interface. func (err cerr) Error() string { return string(err) } -// ErrMissingDataName is set when a multipart variable/file has no name="..." -const ErrMissingDataName = cerr("data has no name") +// errMissingDataName is set when a multipart variable/file has no name="..." +const errMissingDataName = cerr("data has no name") -// ErrDataNameConflict is set when a multipart variable/file name is already used -const ErrDataNameConflict = cerr("data name conflict") +// errDataNameConflict is set when a multipart variable/file name is already used +const errDataNameConflict = cerr("data name conflict") -// ErrNoHeader is set when a multipart variable/file has no (valid) header -const ErrNoHeader = cerr("data has no header") +// errNoHeader is set when a multipart variable/file has no (valid) header +const errNoHeader = cerr("data has no header") // Component represents a multipart variable/file type Component struct { diff --git a/internal/multipart/reader.go b/internal/multipart/reader.go index affb80a..eaa8449 100644 --- a/internal/multipart/reader.go +++ b/internal/multipart/reader.go @@ -71,11 +71,11 @@ func (reader *Reader) Parse() error { name := comp.GetHeader("name") if len(name) < 1 { - return ErrMissingDataName + return errMissingDataName } if _, nameUsed := reader.Data[name]; nameUsed { - return ErrDataNameConflict + return errDataNameConflict } reader.Data[name] = comp diff --git a/internal/multipart/reader_test.go b/internal/multipart/reader_test.go index 0c4cc02..fa3dfdb 100644 --- a/internal/multipart/reader_test.go +++ b/internal/multipart/reader_test.go @@ -196,8 +196,8 @@ func TestNoName(t *testing.T) { return } - if err = mpr.Parse(); err != ErrMissingDataName { - t.Errorf("expected the error <%s>, got <%s>", ErrMissingDataName, err) + if err = mpr.Parse(); err != errMissingDataName { + t.Errorf("expected the error <%s>, got <%s>", errMissingDataName, err) return } }) @@ -238,8 +238,8 @@ func TestNoHeader(t *testing.T) { return } - if err = mpr.Parse(); err != ErrNoHeader { - t.Errorf("expected the error <%s>, got <%s>", ErrNoHeader, err) + if err = mpr.Parse(); err != errNoHeader { + t.Errorf("expected the error <%s>, got <%s>", errNoHeader, err) return } }) @@ -274,8 +274,8 @@ facebook.com t.Fatalf("unexpected error <%s>", err) } - if err = mpr.Parse(); err != ErrDataNameConflict { - t.Fatalf("expected the error <%s>, got <%s>", ErrDataNameConflict, err) + if err = mpr.Parse(); err != errDataNameConflict { + t.Fatalf("expected the error <%s>, got <%s>", errDataNameConflict, err) } }