maputil

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Difference

func Difference[K comparable, V any](m map[K]V, keys ...K) map[K]V

Difference returns the inputted map without the keys specified as input.

func Flatten

func Flatten(m map[string]any, separator string) map[string]any

Flatten takes a map and returns a new one where nested maps are replaced by dot-delimited keys.

func GetKeys

func GetKeys[K comparable, V any](maps ...map[K]V) []K

GetKeys returns the map's keys.

func GetValues

func GetValues[K comparable, V any](maps ...map[K]V) []V

GetValues returns the map's values.

func Walk

func Walk(m map[string]any, callback func(k string, v any))

Walk a map and visit all the edge key:value pairs

Types

type HTTPRequestMap

type HTTPRequestMap map[string]interface{}

HTTPRequestMap is a map representation of the request

Example:

{
	"request": {
		"method": "POST",
		"path": "/foo/bar",
		"body": "foo=1&bar=test",
		"raw": "GET /foo/bar?one=testone&two=testtwo HTTP/1.1\nSome-Header: test\n\nfoo=1&bar=test"
	},
	"headers": {
		"Some-Header": "test"
	},
	"query_params": {
		"one": "testone",
		"two": "testtwo"
	}
}

func NewHTTPRequestMap

func NewHTTPRequestMap(req *http.Request) (HTTPRequestMap, error)

func (HTTPRequestMap) Body

func (hrm HTTPRequestMap) Body() string

Body returns request's body as string

func (HTTPRequestMap) Headers

func (hrm HTTPRequestMap) Headers() http.Header

Headers returns all header as http.Header instance

func (HTTPRequestMap) Method

func (hrm HTTPRequestMap) Method() string

Method returns request's method

func (HTTPRequestMap) Path

func (hrm HTTPRequestMap) Path() string

Path returns request's req.URL.Path

func (HTTPRequestMap) QueryParams

func (hrm HTTPRequestMap) QueryParams() url.Values

QueryParams returns all query params as url.Values instance

func (HTTPRequestMap) Request

func (hrm HTTPRequestMap) Request() (*http.Request, error)

Request returns http.Request instance by loading from raw request

type HTTPResponseMap

type HTTPResponseMap map[string]interface{}

HTTPResponseMap is a map representation of the response

Example:

{
	"request": {
		"raw": "GET /foo/bar?one=testone&two=testtwo HTTP/1.1\nSome-Header: test\n\nfoo=1&bar=test"
	},
	"response": {
		"content_length": "2034",
		"status_code": "200",
		"body": "<html>....</html>"
		"raw": "HTTP/2 200 OK\nSome-Header: test\n\n<html>....</html>"
	},
	"headers": {
		"Some-Header": "test"
	}
}

func NewHTTPResponseMap

func NewHTTPResponseMap(resp *http.Response) (HTTPResponseMap, error)

func (HTTPResponseMap) Body

func (hrm HTTPResponseMap) Body() string

Body returns response's body as string

func (HTTPResponseMap) ContentLength

func (hrm HTTPResponseMap) ContentLength() int

ContentLength returns response's content length

func (HTTPResponseMap) Headers

func (hrm HTTPResponseMap) Headers() http.Header

Headers returns all header as http.Header instance

func (HTTPResponseMap) Response

func (hrm HTTPResponseMap) Response() (*http.Response, error)

Response returns http.Response instance by loading from raw request

func (HTTPResponseMap) StatusCode

func (hrm HTTPResponseMap) StatusCode() int

StatusCode returns response's status code

Jump to

Keyboard shortcuts

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