echoform

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 6 Imported by: 0

README

Wrapper for echo

Usage

Example data
--boundary
Content-Disposition: form-data; name="name"

mazrean
--boundary
Content-Disposition: form-data; name="password"

password
--boundary
Content-Disposition: form-data; name="icon"; filename="icon.png"
Content-Type: image/png

icon contents
--boundary--
func createUserHandler(c echo.Context) error {
	parser, err := echoform.NewParser(c)
	if err != nil {
		return c.NoContent(http.StatusBadRequest)
	}

	err = parser.Register("icon", func(r io.Reader, header formstream.Header) error {
		name, _, _ := parser.Value("name")
		password, _, _ := parser.Value("password")

		return saveUser(c.Request().Context(), name, password, r)
	}, formstream.WithRequiredPart("name"), formstream.WithRequiredPart("password"))
	if err != nil {
		return err
	}

	err = parser.Parse()
	if err != nil {
		return c.NoContent(http.StatusBadRequest)
	}

	return c.NoContent(http.StatusCreated)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	*formstream.Parser
	// contains filtered or unexported fields
}

func NewParser

func NewParser(c echo.Context, options ...formstream.ParserOption) (*Parser, error)

func (*Parser) Parse

func (p *Parser) Parse() error

Parse parses the request body. It returns the echo.HTTPError if the hook function returns an echo.HTTPError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL