requests

package
v0.0.1-alpha.0...-700cb3a Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Base ...

View Source
var DefaultSender = &defaultSender{}
View Source
var ErrUnmarshalEmpty = errors.New("could not unmarshal an empty buffer")

ErrUnmarshalEmpty ...

View Source
var JSON = Base.Header("Content-Type", "application/json")

JSON ...

Functions

func ComputeSubsequentRecordURLs

func ComputeSubsequentRecordURLs(instanceURL string, firstNextRecordsURL string, secondNextRecordsURL string, totalRecords int) (URLs []string, err error)

ComputeSubsequentRecordURLs identifies the cursor used for a query with multiple results pages and computes all subsequent page urls from the first two requests

i.e. query /query?q=select Name from Lead => returns firstNextRecordsURL: "some-url-1000" query firstNextRecordsURL => returns secondNextRecordsURL "some-url-2000" <-- calculate the increment computeSubsequentRecordURLs(firstNextRecordsURL, secondNextRecordsURL)

this allows us to then query asynchronously the remaining records asynchronously rather then walking them one at a time

NOTE: this behavior is dependant on salesforce pagination being predetermined after the first two requests. as far as I know, this implementation is undocumented and could change at any time. though it is VERY convenient and offers a massive performance improvement.

func ExtractUsageHeader

func ExtractUsageHeader(response *http.Response) (used int64, total int64, err error)

ExtractUsageHeader extracts two integer value from the Sforce-Limit-Info header which contains a formatted string containing that information

Because we are extracting integer data from a complex string, this process is prone to error if an unexpected value is found

func MergeJSONArrays

func MergeJSONArrays(arrays ...[]byte) []byte

MergeJSONArrays takes many potentially large JSON arrays and merges them into a single array that can be unmarshalled into a single slice. Because of the performance impact of iterating through the entirety of an array we attempt to operate only on the first and last characters of the array.

This method is used to create better API signatures when bulk querying - where methods further down the call stack are re-used and don't know the specific type of the response but need to combine them anyways.

The same result can probably be achieved with less effort via the reflect package but this solution is succinct and works well enough.

There is also room to optimize memory usage by pre-computing the length of the final output.

func MustURL

func MustURL(str string, values *url.Values) *url.URL

MustURL ...

func ReadAndCloseResponse

func ReadAndCloseResponse(r *http.Response) ([]byte, error)

ReadAndCloseResponse is a safety function that ensures we do not leak system resources by closing the http.Response Body after it is read

The semantics of body.Close() are a little confusing in Golang and because of the quantity of http requests we make in our applications it is easy to run out of system resources such as file descriptors

func Unmarshal

func Unmarshal(r *http.Response, dst interface{}) ([]byte, error)

Unmarshal reads and closes an http response body it returns the raw bytes of the body and any error which occurred

this utility function reduces the boilerplate code necessary for unmarshaling http.Response bodies

Types

type Builder

type Builder builder.Builder

Builder ...

func JSONURL

func JSONURL(url string) Builder

JSONURL ...

func Sender

func Sender(sender sender) Builder

Sender ...

func URL

func URL(url string) Builder

URL ...

func (Builder) Body

func (b Builder) Body(body io.Reader) Builder

Body ...

func (Builder) Context

func (b Builder) Context(ctx context.Context) Builder

Context ...

func (Builder) Header

func (b Builder) Header(key string, values ...string) Builder

Header appends a single header to any existing headers

func (Builder) Headers

func (b Builder) Headers(header http.Header) Builder

Headers ...

func (Builder) JSON

func (b Builder) JSON(dst interface{}) (body []byte, err error)

JSON ...

func (Builder) Marshal

func (b Builder) Marshal(item interface{}) Builder

Marshal ...

func (Builder) Method

func (b Builder) Method(method string) Builder

Method ...

func (Builder) Param

func (b Builder) Param(key, value string) Builder

Param ...

func (Builder) QueryMore

func (b Builder) QueryMore(selectBuilder soql.Builder, dst interface{}, includeSoftDelete bool) error

QueryMore ...

func (Builder) Request

func (b Builder) Request() (*http.Request, error)

Request composes an http.Request from its base components: * a url string [REQUIRED] * an http method string [OPTIONAL, DEFAULT = http.MethodGet] * url parameters aka url.Values [OPTIONAL] * a request body [OPTIONAL] * http headers [OPTIONAL]

func (Builder) Response

func (b Builder) Response() (*http.Response, error)

Response ...

func (Builder) SQLizer

func (b Builder) SQLizer(sqlizer sqlizer) Builder

SQLizer ...

func (Builder) Sender

func (b Builder) Sender(sender sender) Builder

Sender ...

func (Builder) URL

func (b Builder) URL(str string) Builder

URL ...

func (Builder) Values

func (b Builder) Values(values url.Values) Builder

Values ...

type RequestError

type RequestError struct {
	Code     int
	Contents []byte
	Err      error
}

RequestError contains additional metadata about the http error

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Is

func (e *RequestError) Is(tgt error) bool

Is ...

func (*RequestError) Unmarshal

func (e *RequestError) Unmarshal(dst interface{}) error

Unmarshal ...

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

Jump to

Keyboard shortcuts

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