request

package
v0.0.0-...-857c71f Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StackSourceFileName     = "source"
	StackSourceLineName     = "line"
	StackSourceFunctionName = "func"
)
View Source
var IsProduction bool

Nothing to describe this fucking variable.

Functions

func MarshalStackSkip

func MarshalStackSkip(skip int) func(err error) interface{}

func MustAdmin

func MustAdmin(out *ent.Admin) echo.HandlerFunc

required middleware jwtService.RequiredAdmin()

func MustAdminContext

func MustAdminContext(out *appctx.AdminContext) echo.HandlerFunc

required middleware jwtService.RequiredAdmin()

func MustRqlParser

func MustRqlParser(config rql.Config) *rql.Parser

Model is the resource definition. The parser is configured based on the its definition. For example, given the following struct definition: note: for admin only

type User struct {
    Age	 int	`rql:"filter,sort"`
    Name string	`rql:"filter"`
}

Json

{
  "limit": 25,
  "offset": 0,
  "filter": {
    "isEnable": true,
    "createdAt": {
      "$gt": "2018-01-01T16:00:00.000Z",
      "$lt": "2018-04-01T16:00:00.000Z"
    }
    "$or": [
      { "isEnable": false },
      { "address": "NYC" }
    ]
  }
  "sort": ["-id","createdAt","+isEnable"]
}

func Parse

func Parse(parser Parser, parsers ...Parser) echo.HandlerFunc

simple parser Parse(BodyParser(&body),ParamsParser(out))

func ParseUrlQuery

func ParseUrlQuery(v string) string

ParseUrlQuery

queries := "filter[money][gt]=true&limit=10"
expected := `{"filter":{"money":{"gt":true}},"limit":100}`

func Response

func Response(c echo.Context, opts ...response.ReponseOption) error

A fuction to return beautiful and structured responses.

Response(c,response.Data(...))

{
	code:0,
	message:"OK"
	data:any
}

Response(c)

{
	code:0,
	message:"OK"
	data:any
}

Response(c,response.Error(...))

{
	code:-5,
	message:".....error"
}

func Validate

func Validate(parser Parser, parsers ...Parser) echo.HandlerFunc

use as middleware Validate(BodyParser(&body),ParamsParser(out))

Types

type Parser

type Parser func(c echo.Context) (any, error)

func BodyParser

func BodyParser(out any) Parser

BodyParser(&Person{})

type User struct {
  ID string `param:"id" query:"id" form:"id" json:"id" xml:"id"`
}

Swagger

// @Param 		<name> <params-type> <value-type> <required> <description>
// @Param 		info body dto.RouteRequest true "Route Info"

func ParamsParser

func ParamsParser(out any) Parser

ParamsParser(&param{})

param := new(struct {ID uint `param:"id"`})

Swagger

// @Param       <name> <params-type> <value-type> <required> <description>
// @Param       id path int true "Route ID"

func QueryParser

func QueryParser(out any) Parser

QueryParser(&Person{})

type Person struct {
    Name     string     `query:"name"`
    Pass     string     `query:"pass"`
    Products []string   `query:"products"`
}

Swagger

// @Param       <name> <params-type> <value-type> <required> <description>
// @Param       person query dto.Person true "person info"

func RqlQueryParser

func RqlQueryParser(out *rql.Params, parser *rql.Parser) Parser

@Required: meta.use(RQL(...))

https://github.com/a8m/rql

{
  "limit": 25,
  "filter": {
    "admin": false,
    "createdAt": {
      "$gt": "2018-01-01T16:00:00.000Z",
      "$lt": "2018-04-01T16:00:00.000Z"
    }
    "$or": [
      { "address": "TLV" },
      { "address": "NYC" }
    ]
  }
  "sort": ["-createdAt"]
}

Jump to

Keyboard shortcuts

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