httpunix

package
v0.0.0-...-42c81d0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example (Integrated)
package main

import (
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
	"time"

	"bazil.org/bazil/util/httpunix"
)

func main() {
	u := &httpunix.HTTPUnixTransport{
		DialTimeout:           100 * time.Millisecond,
		RequestTimeout:        1 * time.Second,
		ResponseHeaderTimeout: 1 * time.Second,
	}
	u.RegisterLocation("foo", "sock")

	// If you want to use http: with the same client:
	t := &http.Transport{}
	t.RegisterProtocol(httpunix.Scheme, u)
	var client = http.Client{
		Transport: t,
	}

	resp, err := client.Get("http+unix://foo/bar")
	if err != nil {
		log.Fatal(err)
	}
	buf, err := httputil.DumpResponse(resp, true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", buf)
	resp.Body.Close()
}
Output:

Example (Standalone)
package main

import (
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
	"time"

	"bazil.org/bazil/util/httpunix"
)

func main() {
	u := &httpunix.HTTPUnixTransport{
		DialTimeout:           100 * time.Millisecond,
		RequestTimeout:        1 * time.Second,
		ResponseHeaderTimeout: 1 * time.Second,
	}
	u.RegisterLocation("foo", "sock")

	var client = http.Client{
		Transport: u,
	}

	resp, err := client.Get("http+unix://foo/bar")
	if err != nil {
		log.Fatal(err)
	}
	buf, err := httputil.DumpResponse(resp, true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", buf)
	resp.Body.Close()
}
Output:

Index

Examples

Constants

View Source
const Scheme = "http+unix"

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPUnixTransport

type HTTPUnixTransport struct {
	DialTimeout           time.Duration
	RequestTimeout        time.Duration
	ResponseHeaderTimeout time.Duration
	// contains filtered or unexported fields
}

func (*HTTPUnixTransport) RegisterLocation

func (u *HTTPUnixTransport) RegisterLocation(loc string, path string)

func (*HTTPUnixTransport) RoundTrip

func (t *HTTPUnixTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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