urlvalues

package module
v0.0.0-...-f68d16c Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2016 License: MIT Imports: 3 Imported by: 1

README

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.

Documentation

Overview

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 (https://github.com/gorilla/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())
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder struct {
	TagID string
}

Encoder encodes values from a struct into url.Values.

func NewEncoder

func NewEncoder() *Encoder

NewEncoder returns a new Encoder with defaults.

func (*Encoder) Encode

func (e *Encoder) Encode(src interface{}, dst map[string][]string) error

Encode encodes a struct into map[string][]string.

Intended for use with url.Values.

func (*Encoder) SetAliasTag

func (e *Encoder) SetAliasTag(tag string) *Encoder

SetAliasTag changes the tag used to locate urlvalues annotations. The default value is "url"

Jump to

Keyboard shortcuts

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