query

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2016 License: MIT Imports: 2 Imported by: 0

README

gentleman/query Build Status GoDoc API Go Report Card

gentleman's plugin to easily manage HTTP query params.

Installation

go get -u gopkg.in/h2non/gentleman.v0/plugins/query

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v0"
  "gopkg.in/h2non/gentleman.v0/plugins/query"
  "gopkg.in/h2non/gentleman.v0/plugins/url"
)

func main() {
  // Create a new client
  cli := gentleman.New()

  // Define the base URL to use
  cli.Use(url.BaseURL("http://httpbin.org"))
  cli.Use(url.Path("/get"))

  // Define a custom query param
  cli.Use(query.Set("foo", "bar"))

  // Remove a query param
  cli.Use(query.Del("bar"))

  // Perform the request
  res, err := cli.Request().Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
    return
  }
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)
    return
  }

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())
}

License

MIT - Tomas Aparicio

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(key, value string) p.Plugin

Add adds the query param value to key. It appends to any existing values associated with key.

func Del

func Del(key string) p.Plugin

Del deletes the query param values associated with key.

func DelAll

func DelAll() p.Plugin

DelAll deletes all the query params.

func Set

func Set(key, value string) p.Plugin

Set sets the query param key and value. It replaces any existing values.

func SetMap

func SetMap(params map[string]string) p.Plugin

SetMap sets a map of query params by key-value pair.

Types

This section is empty.

Jump to

Keyboard shortcuts

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