reqparser

package module
v0.0.0-...-5c92939 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

README

ReqParser

multiparser for fiber request parser interface

Idea

main idea was make the request more clean, rather than:

before
var request RequestStruct
err := c.BodyParser(&request)
if err != nil {
    return err
}
after
request, err := reqparser.New[RequestStruct](c).Parse(reqparser.BodyParser())
if err != nil {
    return err
}
or
id, err := reqparser.New[string](c).Parse(reqparser.Params("id", true))
if err != nil {
    return err
}

License

GNU

Contribute

Pull Request are pleased to

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModifyAllowedFileExt

func ModifyAllowedFileExt(extensions []string)

func ModifyDefaultPathFile

func ModifyDefaultPathFile(path string)

func SaveFileToStorage

func SaveFileToStorage(c FiberInterface, fieldName string, required bool) (string, error)

Types

type CustomError

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

func NewCommonError

func NewCommonError(field, message string) CustomError

func (CustomError) Error

func (e CustomError) Error() string

type FiberInterface

type FiberInterface interface {
	BodyParser(out interface{}) error
	QueryParser(out interface{}) error
	FormValue(key string, defaultValue ...string) string
	Params(key string, defaultValue ...string) string
	Query(key string, defaultValue ...string) string
	FormFile(key string) (*multipart.FileHeader, error)
}

type Parser

type Parser[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](c FiberInterface) *Parser[T]

func (*Parser[T]) Parse

func (p *Parser[T]) Parse(rules ...RulesFunc) (v T, err error)

type RuleSet

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

type RulesFunc

type RulesFunc func() RuleSet

func BodyParser

func BodyParser() RulesFunc

func File

func File(key string, required bool) RulesFunc

func Form

func Form(key string, required bool) RulesFunc

func Params

func Params(key string, required bool) RulesFunc

func Query

func Query(key string, required bool) RulesFunc

func QueryParser

func QueryParser() RulesFunc

Jump to

Keyboard shortcuts

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