headers

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/headers Build Status GoDoc API Go Report Card

gentleman's plugin to easily manage HTTP headers.

Installation

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

API

See godoc reference.

Example

package main

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

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

  // Define a custom header
  cli.Use(headers.Set("API-Token", "s3cr3t"))

  // Remove a header
  cli.Use(headers.Del("User-Agent"))

  // Perform the request
  res, err := cli.Request().URL("http://httpbin.org/headers").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 key, value pair to the header. It appends to any existing values associated with key.

func Del

func Del(key string) p.Plugin

Del deletes the header fields associated with key.

func Set

func Set(key, value string) p.Plugin

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func SetMap

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

SetMap sets a map of headers represented 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