parsers

package
v1.23.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchFixtureQuery

func MatchFixtureQuery(value string) (*regexp.Regexp, bool)

MatchFixtureQuery will attempt to find matches for a fixture query pattern returning a *Regexp which can be used to further parse and a boolean indicating a match was found.

func ParseArrayForFormData added in v1.21.6

func ParseArrayForFormData(params []interface{}, parent string, queryRespMap map[string]gjson.Result) ([]string, error)

ParseArrayForFormData is similar to parseMap but doesn't have to build the multi-depth keys. Form data arrays contain brackets with nothing inside the bracket to designate an array instead of a key value pair.

func ParseMapForFormData added in v1.21.6

func ParseMapForFormData(params map[string]interface{}, parent string, index int, queryRespMap map[string]gjson.Result) ([]string, error)

ParseMapForFormData recursively parses a map of string => interface{} until each leaf node has a terminal type (String, Int, etc) that can no longer be recursively traversed.

func ParsePath

func ParsePath(httpPath string, queryRespMap map[string]gjson.Result) (string, error)

ParsePath will inspect the path to see if it has a query in the path for requests that operate on specific objects (for example, GET /v1/customers/:id or POST /v1/subscriptions/:id)

If a query is found, this returns the path with the value already in place. If there is no query, it returns the old path as-is.

func ParseQuery

func ParseQuery(queryString string, queryRespMap map[string]gjson.Result) (string, error)

ParseQuery checks strings for possible queries and replaces the corresponding value in its place. The supported query format is:

$<name of fixture>:dot.path.to.field

func ParseToApplicationJSON added in v1.21.6

func ParseToApplicationJSON(params interface{}, queryRespMap map[string]gjson.Result) (interface{}, error)

ParseToApplicationJSON is the primary entrypoint into building the request data for v2 fixtures. The data will always be provided as an interface{} and this will need to use reflection to determine how to proceed. There are two primary paths here, `parseMap` and `ParseArray`, which will recursively traverse and convert the data

This returns an interface of clean application/json data to make the request.

func ParseToFormData added in v1.21.6

func ParseToFormData(params interface{}, queryRespMap map[string]gjson.Result) ([]string, error)

ParseToFormData is the primary entrypoint into building the request data for fixtures. The data will always be provided as an interface{} and this will need to use reflection to determine how to proceed. There are two primary paths here, `parseMap` and `ParseArray`, which will recursively traverse and convert the data

This returns an array of clean form data to make the request.

Types

type FixtureQuery

type FixtureQuery struct {
	Match        string // The substring that matched the query pattern regex
	Name         string
	Query        string
	DefaultValue string
}

FixtureQuery describes the query in fixture request

func ToFixtureQuery

func ToFixtureQuery(value string) (FixtureQuery, bool)

ToFixtureQuery will parse a string into a fixtureQuery struct, additionally returning a bool indicating the value did contain a fixtureQuery.

Jump to

Keyboard shortcuts

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