grequests

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 25 Imported by: 1

README

grequest

根据grequests改的

Documentation

Overview

Package grequests implements a friendly API over Go's existing net/http library

Example (AcceptInvalidTLSCert)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	ro := grequests.InsecureSkipVerify(true)
	resp, err := grequests.Get("https://www.pcwebshop.co.uk/", ro)

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (BasicAuth)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	ro := grequests.Auth([]string{"Levi", "Bot"})
	resp, err := grequests.Get("http://httpbin.org/get", ro)
	// Not the usual JSON so copy and paste from below

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (BasicGet)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	// This is a very basic GET request
	resp, err := grequests.Get("http://httpbin.org/get", nil)

	if err != nil {
		log.Println(err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
Output:

Example (BasicGetCustomHTTPClient)
package main

import (
	"log"
	"net/http"

	"github.com/open-api-go/grequests"
)

func main() {
	// This is a very basic GET request
	resp, err := grequests.Get("http://httpbin.org/get", grequests.HTTPClient(http.DefaultClient))

	if err != nil {
		log.Println(err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
Output:

Example (Cookies)
package main

import (
	"log"
	"net/http"

	"github.com/open-api-go/grequests"
)

func main() {
	resp, err := grequests.Get("http://httpbin.org/cookies",
		grequests.Cookies([]*http.Cookie{
			{
				Name:     "TestCookie",
				Value:    "Random Value",
				HttpOnly: true,
				Secure:   false,
			}, {
				Name:     "AnotherCookie",
				Value:    "Some Value",
				HttpOnly: true,
				Secure:   false,
			},
		}),
	)

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
Output:

Example (CustomHTTPHeader)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	ro := []grequests.RequestOption{grequests.UserAgent("LeviBot 0.1"),
		grequests.Headers(map[string]string{"X-Wonderful-Header": "1"})}
	resp, err := grequests.Get("http://httpbin.org/get", ro...)
	// Not the usual JSON so copy and paste from below

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (CustomUserAgent)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	ro := grequests.UserAgent("LeviBot 0.1")
	resp, err := grequests.Get("http://httpbin.org/get", ro)

	if err != nil {
		log.Fatal("Oops something went wrong: ", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())
}
Output:

Example (DownloadFile)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	resp, err := grequests.Get("http://httpbin.org/get", nil)

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	if err := resp.DownloadToFile("randomFile"); err != nil {
		log.Println("Unable to download to file: ", err)
	}

	if err != nil {
		log.Println("Unable to download file", err)
	}

}
Output:

Example (Parse_XML)
package main

import (
	"encoding/xml"
	"io"
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	type GetXMLSample struct {
		XMLName xml.Name `xml:"slideshow"`
		Title   string   `xml:"title,attr"`
		Date    string   `xml:"date,attr"`
		Author  string   `xml:"author,attr"`
		Slide   []struct {
			Type  string `xml:"type,attr"`
			Title string `xml:"title"`
		} `xml:"slide"`
	}

	resp, err := grequests.Get("http://httpbin.org/xml", nil)

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	userXML := &GetXMLSample{}

	// func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
	// 	return input, nil
	// }

	// If the server returns XML encoded in another charset (not UTF-8) – you
	// must provide an encoder function that looks like the one I wrote above.

	// If you an consuming UTF-8 just pass `nil` into the second arg
	if err := resp.XML(userXML, xmlASCIIDecoder); err != nil {
		log.Println("Unable to consume the response as XML: ", err)
	}

	if userXML.Title != "Sample Slide Show" {
		log.Printf("Invalid XML serialization %#v", userXML)
	}
}

func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
	return input, nil
}
Output:

Example (PostFileUpload)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {

	fd, err := grequests.FileUploadFromDisk("test_files/mypassword")

	if err != nil {
		log.Println("Unable to open file: ", err)
	}

	// This will upload the file as a multipart mime request
	resp, err := grequests.Post("http://httpbin.org/post",
		grequests.Files(fd),
		grequests.Data(map[string]string{"One": "Two"}),
	)

	if err != nil {
		log.Println("Unable to make request", resp.Error)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (PostForm)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	resp, err := grequests.Post("http://httpbin.org/post",
		grequests.Data(map[string]string{"One": "Two"}))

	// This is the basic form POST. The request body will be `one=two`

	if err != nil {
		log.Println("Cannot post: ", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (PostJSONAJAX)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	resp, err := grequests.Post("http://httpbin.org/post",
		grequests.JSON(map[string]string{"One": "Two"}),
		grequests.IsAjax(true), // this adds the X-Requested-With: XMLHttpRequest header
	)

	if err != nil {
		log.Println("Unable to make request", resp.Error)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

}
Output:

Example (PostXML)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {

	type XMLPostMessage struct {
		Name   string
		Age    int
		Height int
	}

	resp, err := grequests.Post("http://httpbin.org/post",
		grequests.XML(XMLPostMessage{Name: "Human", Age: 1, Height: 1}))
	// The request body will contain the XML generated by the `XMLPostMessage` struct

	if err != nil {
		log.Println("Unable to make request", resp.Error)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Example (Proxy)
package main

import (
	"log"
	"net/url"

	"github.com/open-api-go/grequests"
)

func main() {
	proxyURL, err := url.Parse("http://127.0.0.1:8080") // Proxy URL
	if err != nil {
		log.Panicln(err)
	}

	resp, err := grequests.Get("http://www.levigross.com/",
		grequests.Proxies(map[string]*url.URL{proxyURL.Scheme: proxyURL}))

	if err != nil {
		log.Println(err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp)
}
Output:

Example (Session)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	session := grequests.NewSession(nil)

	resp, err := session.Get("http://httpbin.org/cookies/set", grequests.Params(map[string]string{"one": "two"}))

	if err != nil {
		log.Fatal("Cannot set cookie: ", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}

	log.Println(resp.String())

}
Output:

Example (UrlQueryParams)
package main

import (
	"log"

	"github.com/open-api-go/grequests"
)

func main() {
	ro := grequests.Params(map[string]string{"Hello": "World", "Goodbye": "World"})
	resp, err := grequests.Get("http://httpbin.org/get", ro)
	// url will now be http://httpbin.org/get?hello=world&goodbye=world

	if err != nil {
		log.Println("Unable to make request", err)
	}

	if resp.Ok != true {
		log.Println("Request did not return OK")
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrRedirectLimitExceeded is the error returned when the request responded
	// with too many redirects
	ErrRedirectLimitExceeded = errors.New("grequests: Request exceeded redirect count")

	// RedirectLimitNum is a tunable variable that specifies how many times we can
	// redirect in response to a redirect. This is the global variable, if you
	// wish to set this on a request by request basis, set it within the
	// `RequestOptions` structure
	RedirectLimitNum = 30

	// SensitiveHeaders is a map of sensitive HTTP headers that a user
	// doesn't want passed on a redirect. This is the global variable, if you
	// wish to set this on a request by request basis, set it within the
	// `RequestOptions` structure
	SensitiveHeaders = map[string]struct{}{
		"Www-Authenticate":    {},
		"Authorization":       {},
		"Proxy-Authorization": {},
	}
)

Functions

func BuildHTTPClient

func BuildHTTPClient(ro RequestOptions) *http.Client

BuildHTTPClient is a function that will return a custom HTTP client based on the request options provided the check is in UseDefaultClient

func EnsureTransporterFinalized

func EnsureTransporterFinalized(httpTransport *http.Transport)

EnsureTransporterFinalized will ensure that when the HTTP client is GCed the runtime will close the idle connections (so that they won't leak) this function was adopted from Hashicorp's go-cleanhttp package

Types

type FileUpload

type FileUpload struct {
	// Filename is the name of the file that you wish to upload. We use this to guess the mimetype as well as pass it onto the server
	FileName string

	// FileContents is happy as long as you pass it a io.ReadCloser (which most file use anyways)
	FileContents io.ReadCloser

	// FieldName is form field name
	FieldName string

	// FileMime represents which mimetime should be sent along with the file.
	// When empty, defaults to application/octet-stream
	FileMime string
}

FileUpload is a struct that is used to specify the file that a User wishes to upload.

func FileUploadFromDisk

func FileUploadFromDisk(fileName string) ([]FileUpload, error)

FileUploadFromDisk allows you to create a FileUpload struct slice by just specifying a location on the disk

func FileUploadFromGlob

func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error)

FileUploadFromGlob allows you to create a FileUpload struct slice by just specifying a glob location on the disk this function will gloss over all errors in the files and only upload the files that don't return errors from the glob

type RequestOption

type RequestOption func(o *RequestOptions)

func Auth

func Auth(a []string) RequestOption

Auth allows you to specify a user name and password that you wish to use when requesting the URL. It will use basic HTTP authentication formatting the username and password in base64 the format is: []string{username, password}

func BeforeRequest

func BeforeRequest(fn func(req *http.Request) error) RequestOption

BeforeRequest is a hook that can be used to modify the request object before the request has been fired. This is useful for adding authentication and other functionality not provided in this library

func Context

func Context(ctx context.Context) RequestOption

Context can be used to maintain state between requests https://golang.org/pkg/context/#Context

func CookieJar

func CookieJar(cj http.CookieJar) RequestOption

CookieJar allows you to specify a special cookiejar to use with your request. this option will take precedence over the `UseCookieJar` option above.

func Cookies

func Cookies(c []*http.Cookie) RequestOption

Cookies is an array of `http.Cookie` that allows you to attach cookies to your request

func Data

func Data(d map[string]string) RequestOption

Data is a map of key values that will eventually convert into the the body of a POST request.

func DialKeepAlive

func DialKeepAlive(d time.Duration) RequestOption

KeepAlive specifies the keep-alive period for an active network connection. If zero

func DialTimeout

func DialTimeout(d time.Duration) RequestOption

DialTimeout is the maximum amount of time a dial will wait for a connect to complete.

func DisableCompression

func DisableCompression(b bool) RequestOption

DisableCompression will disable gzip compression on requests

func Files

func Files(files []FileUpload) RequestOption

Files is where you can include files to upload. The use of this data structure is limited to POST requests

func HTTPClient

func HTTPClient(c *http.Client) RequestOption

HTTPClient can be provided if you wish to supply a custom HTTP client this is useful if you want to use an OAUTH client with your request.

func Headers

func Headers(h map[string]string) RequestOption

Headers if you want to add custom HTTP headers to the request, this is your friend

func Host

func Host(host string) RequestOption

Host allows you to set an arbitrary custom host

func InsecureSkipVerify

func InsecureSkipVerify(b bool) RequestOption

InsecureSkipVerify is a flag that specifies if we should validate the server's TLS certificate. It should be noted that Go's TLS verify mechanism doesn't validate if a certificate has been revoked

func IsAjax

func IsAjax(b bool) RequestOption

IsAjax is a flag that can be set to make the request appear to be generated by browser Javascript

func JSON

func JSON(JSON interface{}) RequestOption

JSON can be used when you wish to send JSON within the request body

func LocalAddr

func LocalAddr(la *net.TCPAddr) RequestOption

LocalAddr allows you to send the request on any local interface

func Params

func Params(p map[string]string) RequestOption

Params is a map of query strings that may be used within a GET request

func Proxies

func Proxies(p map[string]*url.URL) RequestOption

Proxies is a map in the following format *protocol* => proxy address e.g http => http://127.0.0.1:8080

func QueryStruct

func QueryStruct(q interface{}) RequestOption

QueryStruct is a struct that encapsulates a set of URL query params this paramter is mutually exclusive with `Params map[string]string` (they cannot be combined) for more information please see https://godoc.org/github.com/google/go-querystring/query

func RedirectLimit

func RedirectLimit(rl int) RequestOption

RedirectLimit is the acceptable amount of redirects that we should expect before returning an error be default this is set to 30. You can change this globally by modifying the `RedirectLimit` variable.

func RequestBody

func RequestBody(b io.Reader) RequestOption

RequestBody allows you to put anything matching an `io.Reader` into the request this option will take precedence over any other request option specified

func RequestTimeout

func RequestTimeout(d time.Duration) RequestOption

RequestTimeout is the maximum amount of time a whole request(include dial / request / redirect) will wait.

func SensitiveHTTPHeaders

func SensitiveHTTPHeaders(h map[string]struct{}) RequestOption

SensitiveHTTPHeaders is a map of sensitive HTTP headers that a user doesn't want passed on a redirect.

func TLSHandshakeTimeout

func TLSHandshakeTimeout(d time.Duration) RequestOption

TLSHandshakeTimeout specifies the maximum amount of time waiting to wait for a TLS handshake. Zero means no timeout.

func UseCookieJar

func UseCookieJar(b bool) RequestOption

UseCookieJar will create a custom HTTP client that will process and store HTTP cookies when they are sent down

func UserAgent

func UserAgent(ua string) RequestOption

UserAgent allows you to set an arbitrary custom user agent

func XML

func XML(XML interface{}) RequestOption

XML can be used if you wish to send XML within the request body

type RequestOptions

type RequestOptions struct {

	// Data is a map of key values that will eventually convert into the
	// the body of a POST request.
	Data map[string]string

	// Params is a map of query strings that may be used within a GET request
	Params map[string]string

	// QueryStruct is a struct that encapsulates a set of URL query params
	// this paramter is mutually exclusive with `Params map[string]string` (they cannot be combined)
	// for more information please see https://godoc.org/github.com/google/go-querystring/query
	QueryStruct interface{}

	// Files is where you can include files to upload. The use of this data
	// structure is limited to POST requests
	Files []FileUpload

	// JSON can be used when you wish to send JSON within the request body
	JSON interface{}

	// XML can be used if you wish to send XML within the request body
	XML interface{}

	// Headers if you want to add custom HTTP headers to the request,
	// this is your friend
	Headers map[string]string

	// InsecureSkipVerify is a flag that specifies if we should validate the
	// server's TLS certificate. It should be noted that Go's TLS verify mechanism
	// doesn't validate if a certificate has been revoked
	InsecureSkipVerify bool

	// DisableCompression will disable gzip compression on requests
	DisableCompression bool

	// UserAgent allows you to set an arbitrary custom user agent
	UserAgent string

	// Host allows you to set an arbitrary custom host
	Host string

	// Auth allows you to specify a user name and password that you wish to
	// use when requesting the URL. It will use basic HTTP authentication
	// formatting the username and password in base64 the format is:
	// []string{username, password}
	Auth []string

	// IsAjax is a flag that can be set to make the request appear
	// to be generated by browser Javascript
	IsAjax bool

	// Cookies is an array of `http.Cookie` that allows you to attach
	// cookies to your request
	Cookies []*http.Cookie

	// UseCookieJar will create a custom HTTP client that will
	// process and store HTTP cookies when they are sent down
	UseCookieJar bool

	// Proxies is a map in the following format
	// *protocol* => proxy address e.g http => http://127.0.0.1:8080
	Proxies map[string]*url.URL

	// TLSHandshakeTimeout specifies the maximum amount of time waiting to
	// wait for a TLS handshake. Zero means no timeout.
	TLSHandshakeTimeout time.Duration

	// DialTimeout is the maximum amount of time a dial will wait for
	// a connect to complete.
	DialTimeout time.Duration

	// KeepAlive specifies the keep-alive period for an active
	// network connection. If zero, keep-alive are not enabled.
	DialKeepAlive time.Duration

	// RequestTimeout is the maximum amount of time a whole request(include dial / request / redirect)
	// will wait.
	RequestTimeout time.Duration

	// HTTPClient can be provided if you wish to supply a custom HTTP client
	// this is useful if you want to use an OAUTH client with your request.
	HTTPClient *http.Client

	// SensitiveHTTPHeaders is a map of sensitive HTTP headers that a user
	// doesn't want passed on a redirect.
	SensitiveHTTPHeaders map[string]struct{}

	// RedirectLimit is the acceptable amount of redirects that we should expect
	// before returning an error be default this is set to 30. You can change this
	// globally by modifying the `RedirectLimit` variable.
	RedirectLimit int

	// RequestBody allows you to put anything matching an `io.Reader` into the request
	// this option will take precedence over any other request option specified
	RequestBody io.Reader

	// CookieJar allows you to specify a special cookiejar to use with your request.
	// this option will take precedence over the `UseCookieJar` option above.
	CookieJar http.CookieJar

	// Context can be used to maintain state between requests https://golang.org/pkg/context/#Context
	Context context.Context

	// BeforeRequest is a hook that can be used to modify the request object
	// before the request has been fired. This is useful for adding authentication
	// and other functionality not provided in this library
	BeforeRequest func(req *http.Request) error `json:"-"`

	// LocalAddr allows you to send the request on any local interface
	LocalAddr *net.TCPAddr
}

RequestOptions is the location that of where the data

type Response

type Response struct {

	// Ok is a boolean flag that validates that the server returned a 2xx code
	Ok bool

	// This is the Go error flag – if something went wrong within the request, this flag will be set.
	Error error

	// We want to abstract (at least at the moment) the Go http.Response object away. So we are going to make use of it
	// internal but not give the user access
	RawResponse *http.Response

	// StatusCode is the HTTP Status Code returned by the HTTP Response. Taken from resp.StatusCode
	StatusCode int

	// Header is a net/http/Header structure
	Header http.Header
	// contains filtered or unexported fields
}

Response is what is returned to a user when they fire off a request

func Delete

func Delete(url string, opts ...RequestOption) (*Response, error)

Delete takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func DoRegularRequest

func DoRegularRequest(requestVerb, url string, opts ...RequestOption) (*Response, error)

DoRegularRequest adds generic test functionality

func Get

func Get(url string, opts ...RequestOption) (*Response, error)

Get takes 2 parameters and returns a Response Struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Head(url string, opts ...RequestOption) (*Response, error)

Head takes 2 parameters and returns a Response channel. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Options

func Options(url string, opts ...RequestOption) (*Response, error)

Options takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Patch

func Patch(url string, opts ...RequestOption) (*Response, error)

Patch takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Post

func Post(url string, opts ...RequestOption) (*Response, error)

Post takes 2 parameters and returns a Response channel. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Put

func Put(url string, opts ...RequestOption) (*Response, error)

Put takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func Req

func Req(verb string, url string, opts ...RequestOption) (*Response, error)

Req takes 3 parameters and returns a Response Struct. These three options are:

  1. A verb
  2. A URL
  3. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil

func (*Response) Bytes

func (r *Response) Bytes() []byte

Bytes returns the response as a byte array

func (*Response) ClearInternalBuffer

func (r *Response) ClearInternalBuffer()

ClearInternalBuffer is a function that will clear the internal buffer that we use to hold the .String() and .Bytes() data. Once you have used these functions – you may want to free up the memory.

func (*Response) Close

func (r *Response) Close() error

Close is part of our ability to support io.ReadCloser if someone wants to make use of the raw body

func (*Response) DownloadToFile

func (r *Response) DownloadToFile(fileName string) error

DownloadToFile allows you to download the contents of the response to a file

func (*Response) JSON

func (r *Response) JSON(userStruct interface{}) error

JSON is a method that will populate a struct that is provided `userStruct` with the JSON returned within the response body

func (*Response) Read

func (r *Response) Read(p []byte) (n int, err error)

Read is part of our ability to support io.ReadCloser if someone wants to make use of the raw body

func (*Response) String

func (r *Response) String() string

String returns the response as a string

func (*Response) XML

func (r *Response) XML(userStruct interface{}, charsetReader XMLCharDecoder) error

XML is a method that will populate a struct that is provided `userStruct` with the XML returned within the response body

type Session

type Session struct {
	// RequestOptions is global options
	RequestOptions *RequestOptions

	// HTTPClient is the client that we will use to request the resources
	HTTPClient *http.Client
}

Session allows a user to make use of persistent cookies in between HTTP requests

func NewSession

func NewSession(opts ...RequestOption) *Session

NewSession returns a session struct which enables can be used to maintain establish a persistent state with the server This function will set UseCookieJar to true as that is the purpose of using the session

func (*Session) CloseIdleConnections

func (s *Session) CloseIdleConnections()

CloseIdleConnections closes the idle connections that a session client may make use of

func (*Session) Delete

func (s *Session) Delete(url string, opts ...RequestOption) (*Response, error)

Delete takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Get

func (s *Session) Get(url string, opts ...RequestOption) (*Response, error)

Get takes 2 parameters and returns a Response Struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Head

func (s *Session) Head(url string, opts ...RequestOption) (*Response, error)

Head takes 2 parameters and returns a Response channel. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Options

func (s *Session) Options(url string, opts ...RequestOption) (*Response, error)

Options takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Patch

func (s *Session) Patch(url string, opts ...RequestOption) (*Response, error)

Patch takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Post

func (s *Session) Post(url string, opts ...RequestOption) (*Response, error)

Post takes 2 parameters and returns a Response channel. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

func (*Session) Put

func (s *Session) Put(url string, opts ...RequestOption) (*Response, error)

Put takes 2 parameters and returns a Response struct. These two options are:

  1. A URL
  2. A RequestOptions struct

If you do not intend to use the `RequestOptions` you can just pass nil A new session is created by calling NewSession with a request options struct

type XMLCharDecoder

type XMLCharDecoder func(charset string, input io.Reader) (io.Reader, error)

XMLCharDecoder is a helper type that takes a stream of bytes (not encoded in UTF-8) and returns a reader that encodes the bytes into UTF-8. This is done because Go's XML library only supports XML encoded in UTF-8

Jump to

Keyboard shortcuts

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