qs

package module
v0.0.0-...-5421a86 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: MIT Imports: 8 Imported by: 0

README

Guitar String

go-qs

Go port of Rack's query strings

Build Status

This package was written as I haven't found a good package that understands Rack/Rails query string format.

It have been designed to marshal and unmarshal nested query strings from/into map[string]interface{}, inspired on the interface of Go builtin json package.

Compatibility

go-qs is a port of Rack's code. All tests included into test suite are also a port of Rack tests, so this package keeps great compatibility with Rack implementation.

Usage

This package currently relies on libpcre++. Be sure to have it installed on your system before using it. See here for more information.

Unmarshal

To unmarshal query strings to a map[string]interface{}:

package main

import (
  "fmt"
  "github.com/derekstavis/go-qs"
)

query, err := qs.Unmarshal("foo=bar&names[]=foo&names[]=bar")

if err != nil {
  fmt.Printf("%#+v\n", query)
}

The output:

map[string]interface {}{"foo":"bar", "names":[]interface {}{"foo", "bar"}}
Marshal

You can also marshal a map[string]interface{} to a query string:

package main

import (
  "fmt"
  "github.com/derekstavis/go-qs"
)

payload := map[string]interface {}{"foo":"bar", "names":[]interface {}{"foo", "bar"}}

querystring, err := qs.Marshal(payload)

if err != nil {
  fmt.Printf(querystring)
}

The output:

foo=bar&names[]=foo&names[]=bar

License

MIT Copyright (c) 2016 Derek W. Stavis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertArrays

func ConvertArrays(enable bool)

func Marshal

func Marshal(hash map[string]interface{}) (string, error)

func Parse

func Parse(qs string) (interface{}, error)

func Unmarshal

func Unmarshal(qs string) (interface{}, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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