format

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package format provides result formatters for gograph query output. It supports multiple output formats including JSON, XML, YAML, and CSV.

Basic Usage:

formatter := format.NewFormatter("json")
output, err := formatter.Format(result)
if err != nil {
    log.Fatal(err)
}
fmt.Println(output)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVFormatter

type CSVFormatter struct{}

CSVFormatter formats results as CSV.

func (*CSVFormatter) ContentType

func (f *CSVFormatter) ContentType() string

ContentType returns the MIME type for CSV.

func (*CSVFormatter) Format

func (f *CSVFormatter) Format(result cypher.Result) (string, error)

Format converts the result to a CSV string.

type Formatter

type Formatter interface {
	// Format converts a cypher.Result into a formatted string.
	Format(result cypher.Result) (string, error)

	// ContentType returns the MIME type for this formatter.
	ContentType() string
}

Formatter defines the interface for formatting query results.

func NewFormatter

func NewFormatter(name string) Formatter

NewFormatter creates a formatter for the given format name. Supported formats: "json", "xml", "yaml", "csv", "table" (default).

Example:

formatter := format.NewFormatter("json")
output, err := formatter.Format(result)

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter formats results as JSON.

func (*JSONFormatter) ContentType

func (f *JSONFormatter) ContentType() string

ContentType returns the MIME type for JSON.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(result cypher.Result) (string, error)

Format converts the result to a JSON string.

type TableFormatter

type TableFormatter struct{}

TableFormatter formats results as a human-readable table (default).

func (*TableFormatter) ContentType

func (f *TableFormatter) ContentType() string

ContentType returns the MIME type for plain text.

func (*TableFormatter) Format

func (f *TableFormatter) Format(result cypher.Result) (string, error)

Format converts the result to a table string.

type XMLFormatter

type XMLFormatter struct{}

XMLFormatter formats results as XML.

func (*XMLFormatter) ContentType

func (f *XMLFormatter) ContentType() string

ContentType returns the MIME type for XML.

func (*XMLFormatter) Format

func (f *XMLFormatter) Format(result cypher.Result) (string, error)

Format converts the result to an XML string.

type YAMLFormatter

type YAMLFormatter struct{}

YAMLFormatter formats results as YAML-like text.

func (*YAMLFormatter) ContentType

func (f *YAMLFormatter) ContentType() string

ContentType returns the MIME type for YAML.

func (*YAMLFormatter) Format

func (f *YAMLFormatter) Format(result cypher.Result) (string, error)

Format converts the result to a YAML-like string.

Jump to

Keyboard shortcuts

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