common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package common provides some utility functions for dealing with HTTP requests and responses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArraysToMaps

func ArraysToMaps(in interface{}) interface{}

ArraysToMaps creates a copy of the provided interface{}, with all arrays converted into maps where the keys are the array indices, starting at 0. This is useful for formatters where the target serialisation format does not have a means of representing arrays

func Filter

func Filter(in interface{}, path string) (interface{}, error)

Filter takes structured data and returns just the portion of it that matches the provided path using dot notation. The path may contain asterisks, in which case all entries will match at that level of the path e.g. products.*.id will return all product ids

func ForceStringKeys

func ForceStringKeys(in interface{}) interface{}

ForceStringKeys creates a copy of the provided interface{}, with all maps changed to have string keys for use by serialisers that expect string keys This is useful for formatters where the target serialisation format only allows string keys

func MakeRequest

func MakeRequest(method string, url string, input io.Reader, headersIncluded bool) (*http.Response, error)

MakeRequest performs an HTTP request based on the information provided

func Munge

func Munge(left, right interface{}) interface{}

func MungeWithFilter

func MungeWithFilter(left, right interface{}, f FilterFunc) interface{}

func SortedKeys

func SortedKeys(in interface{}) []interface{}

func WriteRequest

func WriteRequest(w io.Writer, req *http.Request, includeMethod bool, includeUrl bool, includeHeaders bool) error

WriteRequest writes an http.Request to the specified writer

func WriteResponse

func WriteResponse(w io.Writer, resp *http.Response, includeHeaders bool, includeStatus bool) error

WriteResponse writes an http.Response to the specified writer

Types

type FilterFunc

type FilterFunc func(reflect.Value, reflect.Value)

Jump to

Keyboard shortcuts

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