record

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBody

func DecodeBody(encodedBody []byte, contentEncodingHeader []string, contentTypeHeader []string) (interface{}, error)

func FilterHeaders

func FilterHeaders(headers map[string][]string, exclude []string) map[string][]string

func Generate

func Generate(config config.Records, payload RecordPayload) ([]byte, error)

func GenerateRequest

func GenerateRequest(recordRequest Request) (*http.Request, error)

func GetContentEncoding

func GetContentEncoding(contentEncodingHeader []string) string

func GetContentType

func GetContentType(contentTypeHeader []string) string

func Gunzip

func Gunzip(data []byte) ([]byte, error)

Gunzip decompresses a gzip-compressed byte slice.

func Gzip

func Gzip(data []byte) ([]byte, error)

Gzip compresses a byte slice using gzip.

func ValidateRecords

func ValidateRecords(records []Record) ([]string, error)

Types

type Metadata

type Metadata struct {
	GeneratedAt   Timestamp `json:"generatedAt"`
	RegeneratedAt Timestamp `json:"regeneratedAt"`
}

type Record

type Record struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
	Metadata Metadata `json:"metadata"`
}

func DecodeRecords

func DecodeRecords(encodedRecords [][]byte) ([]Record, error)

func ExtractRecords

func ExtractRecords(requestBody []byte) ([]Record, error)

type RecordPayload

type RecordPayload struct {
	Hash            string
	Curl            string
	Scheme          string
	HttpMethod      string
	Host            string
	Path            string
	Query           map[string][]string
	RequestHeaders  map[string][]string
	RequestBody     []byte
	StatusCode      int
	ResponseHeaders map[string][]string
	ResponseBody    []byte
}

func GenerateRecordPayload

func GenerateRecordPayload(session Session, hash string, curl string) (RecordPayload, error)

type Request

type Request struct {
	Hash       string              `json:"hash"`
	Curl       string              `json:"curl"`
	Scheme     string              `json:"scheme" validate:"required,oneof=http https"`
	HttpMethod string              `json:"httpMethod" validate:"required,oneof=GET POST PUT DELETE PATCH HEAD CONNECT OPTIONS TRACE"`
	Host       string              `json:"host" validate:"required"`
	Path       string              `json:"path"`
	Query      map[string][]string `json:"query"`
	Headers    map[string][]string `json:"headers"`
	Body       interface{}         `json:"body" validate:"required_if=HttpMethod POST,required_if=HttpMethod PUT,required_if=HttpMethod PATCH"`
}

type Response

type Response struct {
	StatusCode int                 `json:"statusCode" validate:"required"`
	Headers    map[string][]string `json:"headers" validate:"content_type_header_present"`
	Body       interface{}         `json:"body" validate:"required"`
}

type Session

type Session interface {
	SetProp(key string, value interface{})
	GetProp(key string) (interface{}, bool)
	Request() *http.Request
	Response() *http.Response
}

type Timestamp

type Timestamp struct {
	Unix int64     `json:"unix"`
	UTC  time.Time `json:"utc"`
}

Jump to

Keyboard shortcuts

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