dataformat

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 11 Imported by: 3

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"
)

Variables

This section is empty.

Functions

func Encode

func Encode(data map[string]interface{}, dataformat string) (string, error)

Encode encodes the data into a format

func RegisterDataFormat

func RegisterDataFormat(dataformat DataFormat)

RegisterEncoder registers an encoder

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 map[string]interface{}) (string, error)
	// Decode decodes the data from a format
	Decode(input string) (map[string]interface{}, 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 map[string]interface{}
}

Decoded is a decoded data format

func Decode

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

Decode decodes the data from a format

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) (map[string]interface{}, error)

Decode decodes the data from Form format

func (*Form) Encode

func (f *Form) Encode(data map[string]interface{}) (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) (map[string]interface{}, error)

Decode decodes the data from JSON format

func (*JSON) Encode

func (j *JSON) Encode(data map[string]interface{}) (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 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) (map[string]interface{}, error)

Decode decodes the data from MultiPartForm format

func (*MultiPartForm) Encode

func (m *MultiPartForm) Encode(data map[string]interface{}) (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) (map[string]interface{}, error)

Decode decodes the data from Raw format

func (*Raw) Encode

func (r *Raw) Encode(data map[string]interface{}) (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) (map[string]interface{}, error)

Decode decodes the data from XML format

func (*XML) Encode

func (x *XML) Encode(data map[string]interface{}) (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