Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

kladd/urlvalues

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

urlvalues - Golang structs to form values

GoDoc Build Status

Package urlvalues fills form values with the contents of a struct.

This package is meant to be used in conjunction with the gorilla toolkit's schema library, which decodes values into structs.

Example

type Person struct {
	Name  string `url:"name"`
	Phone string `url:"phone"`
}

func main() {
	jane := &Person{"Jane Doe", "(111) 555-5555"}
	vals := url.Values{}

	// Encode Person into url.Values
	encoder := urlvalues.NewEncoder()
	encoder.Encode(jane, vals)

	// Use url.Values.Encode() to output a query string
	// name=Jane+Doe&phone=%28111%29+555-5555
	fmt.Println(vals.Encode())
}

The supported field types so far:

  • bool(&)
  • int(8/16/32/64/&)
  • float(32/64/&)
  • string(&)
  • struct

License

MIT Licensed. See LICENSE.

About

The inverse of gorilla/schema

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages