echoform

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 8 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.NewFormParser(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 EchoContextAdapter

type EchoContextAdapter struct {
	// contains filtered or unexported fields
}

EchoContextAdapter acts as an adapter for an `echo.Context` object. It provides methods to interact with the underlying `echo.Context` object and extract information such as deadline, done channel, error, and values associated with specific keys from the context. The struct is used to enhance the functionality of the `echo.Context` object by providing additional methods and capabilities

func NewEchoContextAdapter

func NewEchoContextAdapter(c echo.Context) *EchoContextAdapter

NewEchoContextAdapter takes echo.Context as a parameter and returns a pointer to a new EchoContextAdapter struct initialized with the provided echo.Context

func (*EchoContextAdapter) Deadline

func (a *EchoContextAdapter) Deadline() (deadline time.Time, ok bool)

Deadline represents the time when the request should be completed deadline returns two values: deadline, which is the deadline time, and ok, indicating if a deadline is set or not

func (*EchoContextAdapter) Done

func (a *EchoContextAdapter) Done() <-chan struct{}

Done channel is used to receive a signal when the request context associated with the EchoContextAdapter is done or canceled

func (*EchoContextAdapter) Err

func (a *EchoContextAdapter) Err() error

Err handles if an error occurred during the processing of the request

func (*EchoContextAdapter) Value

func (a *EchoContextAdapter) Value(key any) any

Value implements the Value method of the context.Context interface used to retrieve a value associated with a specific key from the context

type FormParser

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

func NewFormParser

func NewFormParser(c echo.Context, options ...formstream.ParserOption) (*FormParser, error)

NewFormParser creates a new multipart form parser

func (*FormParser) Parse

func (p *FormParser) 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