Documentation
¶
Overview ¶
pkg/domain/format/converter.go
Package format provides bidirectional conversion between JSON, YAML, and XML formats.
pkg/domain/format/format_converter.go
Index ¶
- type ConversionResult
- type Converter
- type Format
- type FormatConverter
- func (fc *FormatConverter) Convert(ctx context.Context, input any, from Format, to Format) (any, error)
- func (fc *FormatConverter) JSONToXML(ctx context.Context, jsonData any) (any, error)
- func (fc *FormatConverter) JSONToYAML(ctx context.Context, jsonData any) (any, error)
- func (fc *FormatConverter) SupportedFormats() []Format
- func (fc *FormatConverter) SupportsFormat(format Format) bool
- func (fc *FormatConverter) XMLToJSON(ctx context.Context, xmlData any) (any, error)
- func (fc *FormatConverter) XMLToYAML(ctx context.Context, xmlData any) (any, error)
- func (fc *FormatConverter) YAMLToJSON(ctx context.Context, yamlData any) (any, error)
- func (fc *FormatConverter) YAMLToXML(ctx context.Context, yamlData any) (any, error)
- type FormatDetector
- type FormatDetectorImpl
- type UniversalConverter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConversionResult ¶
ConversionResult holds the result of a format conversion
type Converter ¶
type Converter interface {
// Convert transforms data from source format to target format
Convert(ctx context.Context, input any, from Format, to Format) (any, error)
// SupportsFormat checks if a format is supported
SupportsFormat(format Format) bool
// SupportedFormats returns list of supported formats
SupportedFormats() []Format
}
Converter defines the interface for format conversion
type FormatConverter ¶
type FormatConverter struct {
// contains filtered or unexported fields
}
FormatConverter implements format conversion between JSON, YAML, and XML
func NewFormatConverter ¶
func NewFormatConverter() *FormatConverter
NewFormatConverter creates a new format converter
func (*FormatConverter) Convert ¶
func (fc *FormatConverter) Convert(ctx context.Context, input any, from Format, to Format) (any, error)
Convert transforms data from source format to target format
func (*FormatConverter) JSONToYAML ¶
JSONToYAML converts JSON to YAML
func (*FormatConverter) SupportedFormats ¶
func (fc *FormatConverter) SupportedFormats() []Format
SupportedFormats returns list of supported formats
func (*FormatConverter) SupportsFormat ¶
func (fc *FormatConverter) SupportsFormat(format Format) bool
SupportsFormat checks if a format is supported
func (*FormatConverter) YAMLToJSON ¶
YAMLToJSON converts YAML to JSON
type FormatDetector ¶
type FormatDetector interface {
// Detect analyzes data and returns detected format
Detect(data []byte) Format
// CanDetect checks if detector can analyze this data
CanDetect(data []byte) bool
}
FormatDetector attempts to detect format of raw data
type FormatDetectorImpl ¶
type FormatDetectorImpl struct{}
FormatDetectorImpl implements FormatDetector
func NewFormatDetector ¶
func NewFormatDetector() *FormatDetectorImpl
NewFormatDetector creates a new format detector
func (*FormatDetectorImpl) CanDetect ¶
func (fd *FormatDetectorImpl) CanDetect(data []byte) bool
CanDetect checks if detector can analyze this data
func (*FormatDetectorImpl) Detect ¶
func (fd *FormatDetectorImpl) Detect(data []byte) Format
Detect analyzes data and returns detected format
type UniversalConverter ¶
type UniversalConverter interface {
// JSON to YAML
JSONToYAML(ctx context.Context, jsonData any) (any, error)
// JSON to XML
JSONToXML(ctx context.Context, jsonData any) (any, error)
// YAML to JSON
YAMLToJSON(ctx context.Context, yamlData any) (any, error)
// YAML to XML
YAMLToXML(ctx context.Context, yamlData any) (any, error)
// XML to JSON
XMLToJSON(ctx context.Context, xmlData any) (any, error)
// XML to YAML
XMLToYAML(ctx context.Context, xmlData any) (any, error)
}
UniversalConverter converts between any supported formats