dataformat

package
v3.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// JSONDataFormat is the name of the JSON data format
	JSONDataFormat = "json"
	// XMLDataFormat is the name of the XML data format
	XMLDataFormat = "xml"
	// RawDataFormat is the name of the Raw data format
	RawDataFormat = "raw"
	// FormDataFormat is the name of the Form data format
	FormDataFormat = "form"
	// MultiPartFormDataFormat is the name of the MultiPartForm data format
	MultiPartFormDataFormat = "multipart/form-data"
)
View Source
const (
	// DefaultKey is the key i.e used when given
	// data is not of k-v type
	DefaultKey = "value"
)

Variables

This section is empty.

Functions

func Encode

func Encode(data KV, dataformat string) (string, error)

Encode encodes the data into a format

func RegisterDataFormat

func RegisterDataFormat(dataformat DataFormat)

RegisterEncoder registers an encoder

func ToMap added in v3.2.3

func ToMap(m *mapsutil.OrderedMap[string, any]) map[string]interface{}

ToMap converts the ordered map to a map

func ToOrderedMap added in v3.2.3

func ToOrderedMap(data map[string]interface{}) *mapsutil.OrderedMap[string, any]

ToOrderedMap converts the map to an ordered map

Types

type DataFormat

type DataFormat interface {
	// IsType returns true if the data is of the type
	IsType(data string) bool
	// Name returns the name of the encoder
	Name() string
	// Encode encodes the data into a format
	Encode(data KV) (string, error)
	// Decode decodes the data from a format
	Decode(input string) (KV, error)
}

DataFormat is an interface for encoding and decoding

func Get

func Get(name string) DataFormat

Get returns the dataformat by name

type Decoded

type Decoded struct {
	// DataFormat is the data format
	DataFormat string
	// Data is the decoded data
	Data KV
}

Decoded is a decoded data format

func Decode

func Decode(data string) (*Decoded, error)

Decode decodes the data from a format

type FileMetadata added in v3.3.5

type FileMetadata struct {
	ContentType string
	Filename    string
}

type Form

type Form struct{}

func NewForm

func NewForm() *Form

NewForm returns a new Form encoder

func (*Form) Decode

func (f *Form) Decode(data string) (KV, error)

Decode decodes the data from Form format

func (*Form) Encode

func (f *Form) Encode(data KV) (string, error)

Encode encodes the data into Form format

func (*Form) IsType

func (f *Form) IsType(data string) bool

IsType returns true if the data is Form encoded

func (*Form) Name

func (f *Form) Name() string

Name returns the name of the encoder

type JSON

type JSON struct{}

JSON is a JSON encoder

For now JSON only supports objects as the root data type and not arrays

TODO: Support arrays + other JSON oddities by adding more attirbutes to the map[string]interface{}

func NewJSON

func NewJSON() *JSON

NewJSON returns a new JSON encoder

func (*JSON) Decode

func (j *JSON) Decode(data string) (KV, error)

Decode decodes the data from JSON format

func (*JSON) Encode

func (j *JSON) Encode(data KV) (string, error)

Encode encodes the data into JSON format

func (*JSON) IsType

func (j *JSON) IsType(data string) bool

IsType returns true if the data is JSON encoded

func (*JSON) Name

func (j *JSON) Name() string

Name returns the name of the encoder

type KV added in v3.2.3

type KV struct {
	Map        mapsutil.Map[string, any]
	OrderedMap *mapsutil.OrderedMap[string, any]
}

KV is a key-value struct that is implemented or used by fuzzing package to represent a key-value pair sometimes order or key-value pair is important (query params) so we use ordered map to represent the data if it's not important/significant (ex: json,xml) we use map this also allows us to iteratively implement ordered map

func KVMap added in v3.2.3

func KVMap(data map[string]interface{}) KV

KVMap returns a new KV struct with the given map

func KVOrderedMap added in v3.2.3

func KVOrderedMap(data *mapsutil.OrderedMap[string, any]) KV

KVOrderedMap returns a new KV struct with the given ordered map

func (*KV) Clone added in v3.2.3

func (kv *KV) Clone() KV

Clones the current state of the KV struct

func (*KV) Delete added in v3.2.3

func (kv *KV) Delete(key string) bool

Delete deletes a key from the KV struct

func (*KV) Get added in v3.2.3

func (kv *KV) Get(key string) interface{}

Get gets a value from the KV struct

func (*KV) IsNIL added in v3.2.3

func (kv *KV) IsNIL() bool

IsNIL returns true if the KV struct is nil

func (*KV) IsOrderedMap added in v3.2.3

func (kv *KV) IsOrderedMap() bool

IsOrderedMap returns true if the KV struct is an ordered map

func (*KV) Iterate added in v3.2.3

func (kv *KV) Iterate(f func(key string, value any) bool)

Iterate iterates over the KV struct in insertion order

func (*KV) Set added in v3.2.3

func (kv *KV) Set(key string, value any)

Set sets a value in the KV struct

type MultiPartForm

type MultiPartForm struct {
	// contains filtered or unexported fields
}

func NewMultiPartForm

func NewMultiPartForm() *MultiPartForm

NewMultiPartForm returns a new MultiPartForm encoder

func (*MultiPartForm) Decode

func (m *MultiPartForm) Decode(data string) (KV, error)

Decode decodes the data from MultiPartForm format

func (*MultiPartForm) Encode

func (m *MultiPartForm) Encode(data KV) (string, error)

Encode encodes the data into MultiPartForm format

func (*MultiPartForm) IsType

func (m *MultiPartForm) IsType(data string) bool

IsType returns true if the data is MultiPartForm encoded

func (*MultiPartForm) Name

func (m *MultiPartForm) Name() string

Name returns the name of the encoder

func (*MultiPartForm) ParseBoundary

func (m *MultiPartForm) ParseBoundary(contentType string) error

ParseBoundary parses the boundary from the content type

type Raw

type Raw struct{}

func NewRaw

func NewRaw() *Raw

NewRaw returns a new Raw encoder

func (*Raw) Decode

func (r *Raw) Decode(data string) (KV, error)

Decode decodes the data from Raw format

func (*Raw) Encode

func (r *Raw) Encode(data KV) (string, error)

Encode encodes the data into Raw format

func (*Raw) IsType

func (r *Raw) IsType(data string) bool

IsType returns true if the data is Raw encoded

func (*Raw) Name

func (r *Raw) Name() string

Name returns the name of the encoder

type XML

type XML struct{}

XML is an XML encoder

func NewXML

func NewXML() *XML

NewXML returns a new XML encoder

func (*XML) Decode

func (x *XML) Decode(data string) (KV, error)

Decode decodes the data from XML format

func (*XML) Encode

func (x *XML) Encode(data KV) (string, error)

Encode encodes the data into XML format

func (*XML) IsType

func (x *XML) IsType(data string) bool

IsType returns true if the data is XML encoded

func (*XML) Name

func (x *XML) Name() string

Name returns the name of the encoder

Jump to

Keyboard shortcuts

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