requests

package
v0.0.3 Latest Latest
Warning

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

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

README

Requests

A pythonic HTTP library for Gopher with socks5 proxy support

Originally from xephon-b

Usage

Changelog

  • add client struct and default client which wraps http.Client
  • support socks5 proxy https://github.com/dyweb/gommon/issues/18
  • rename GetJSON to get GetJSONStringMap, this should break old Xephon-B code, which is now in tsdb-proxy

Documentation

Overview

Package requests is a pythonic HTTP library for Gopher

Package requests wrap net/http like requests did for python it is easy to use, but not very efficient

Index

Constants

View Source
const (
	ShadowSocksLocal = "127.0.0.1:1080"
	ContentJSON      = "application/json"
)
View Source
const AuthorizationHeader = "Authorization"

Variables

View Source
var TransportBuilder transportBuilder

TODO: might switch to functional options https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis TODO: http proxy? might just use environment variable? https://stackoverflow.com/questions/14661511/setting-up-proxy-for-http-client TransportBuilder is the initial builder, its method return a new copy for chaining and keep itself unchanged

Functions

func ExtractBasicAuth

func ExtractBasicAuth(val string) (username string, password string, err error)

func ExtractBasicAuthFromRequest

func ExtractBasicAuthFromRequest(r *http.Request) (string, string, error)

func GenerateBasicAuth

func GenerateBasicAuth(username string, password string) string

func GetJSON

func GetJSON(url string, data interface{}) error

func GetJSONStringMap

func GetJSONStringMap(url string) (map[string]string, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options ...func(h *http.Client)) (*Client, error)

func (*Client) Get

func (client *Client) Get(url string) (*Response, error)

func (*Client) GetJSON

func (client *Client) GetJSON(url string, data interface{}) error

func (*Client) GetJSONStringMap

func (client *Client) GetJSONStringMap(url string) (map[string]string, error)

func (*Client) PostJSONBytes

func (client *Client) PostJSONBytes(url string, data []byte) (*Response, error)

func (*Client) PostJSONString

func (client *Client) PostJSONString(url string, data string) (*Response, error)

type Response

type Response struct {
	Res  *http.Response
	Text []byte
}

func Get

func Get(url string) (*Response, error)

func PostJSONBytes

func PostJSONBytes(url string, data []byte) (*Response, error)

func PostJSONString

func PostJSONString(url string, data string) (*Response, error)

func (*Response) JSON

func (res *Response) JSON(data interface{}) error

func (*Response) JSONStringMap

func (res *Response) JSONStringMap() (map[string]string, error)

Jump to

Keyboard shortcuts

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