format

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversionResult

type ConversionResult struct {
	Data   any
	Format Format
	Error  error
}

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 Format

type Format string

Format represents supported data formats

const (
	JSON Format = "json"
	YAML Format = "yaml"
	XML  Format = "xml"
)

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

func (fc *FormatConverter) JSONToXML(ctx context.Context, jsonData any) (any, error)

JSONToXML converts JSON to XML

func (*FormatConverter) JSONToYAML

func (fc *FormatConverter) JSONToYAML(ctx context.Context, jsonData any) (any, error)

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

func (fc *FormatConverter) XMLToJSON(ctx context.Context, xmlData any) (any, error)

XMLToJSON converts XML to JSON

func (*FormatConverter) XMLToYAML

func (fc *FormatConverter) XMLToYAML(ctx context.Context, xmlData any) (any, error)

XMLToYAML converts XML to YAML

func (*FormatConverter) YAMLToJSON

func (fc *FormatConverter) YAMLToJSON(ctx context.Context, yamlData any) (any, error)

YAMLToJSON converts YAML to JSON

func (*FormatConverter) YAMLToXML

func (fc *FormatConverter) YAMLToXML(ctx context.Context, yamlData any) (any, error)

YAMLToXML converts YAML to XML

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

Jump to

Keyboard shortcuts

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