Skip to content

slavabobik/xbinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

xbinder

codecov

Bind your struct from http query params

Install

go get -u github.com/slavabobik/xbinder

Example

type Pet struct {
	Name    string
	Age     int
	Hobbies []string
}

func MyHandler(w http.ResponseWriter, r *http.Request) {
	//for e.g. you have a query http://example.com?name=snowball&age=2&hobbies=eat,sleep,repeat
	values := r.URL.Query()

	var pet Pet
	err := xbinder.FromQuery(&pet, values)
	if err != nil {
		// Handle error
	}
}

Supported field types:

  • bool
  • int, int8, int16, int32, int64
  • string
  • int, string slices

Unsupported field types:

  • float
  • pointers
  • uint