easybind

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README

easybind

Bind req arguments easily in Golang. Support Tag pos, specified that where we can get this value, only support one

  • path: from url path, don't support nested struct
  • query: from url query, don't support nested struct
  • body: from request's body, default use json, support nested struct
  • form: from request form
  • required: this value is not null pathQueryier get variables from path, GET /api/v1/users/:id , get id
type Example struct {
	ID   string `json:"id"   pos:"path:id"`             // path value default is required
	Name string `json:"name" pos:"query:name,required"` // query specified that get
}
Get Started
go get github.com/momaek/easybind
Example

please check bind_test.go

Documentation

Index

Constants

View Source
const (
	// DefaultDateFormat day
	DefaultDateFormat = "2006-01-02"
	// DefaultDatetimeFormat minute
	DefaultDatetimeFormat = "2006-01-02 15:0"
	// DefaultDatetimeFormatSecond second
	DefaultDatetimeFormatSecond = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	// TimeFormats supported time formats, also support unix time and time.RFC3339.
	TimeFormats []string

	// TypeBinders bind type
	TypeBinders = make(map[reflect.Type]binder)

	// KindBinders bind kind
	KindBinders = make(map[reflect.Kind]binder)
)

Functions

func Bind

func Bind(req *http.Request, params interface{}, pathQueryier ...interface{}) (err error)

Bind bind params from Path, Query, Body, Form. Donot support binary stream(files, images etc.) Support Tag `pos`, specified that where we can get this value, only support one - path: from url path, don't support nested struct - query: from url query, don't support nested struct - body: from request's body, default use json, support nested struct - form: from request form - required: this value is not null pathQueryier get variables from path, GET /api/v1/users/:id , get id

type Example struct {
	ID   string `json:"id"   pos:"path:id"`             // path value default is required
	Name string `json:"name" pos:"query:name,required"` // query specified that get
}

func BindValue

func BindValue(val string, typ reflect.Type) reflect.Value

BindValue string to specified type

Types

This section is empty.

Jump to

Keyboard shortcuts

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