fc

package module
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: MIT Imports: 23 Imported by: 2

README

fc

FC (Format converter) is a tool to convert different structured data types, like JSON and YAML.

Usage: gofc INPUT_FILTER [FILTER [FILTER [...]]] OUTPUT_FILTER

FILTER := -f <name> [-a arg1 [-a arg2 [...]]]

Installation

go install github.com/spirius/fc/cmd/gofc

Examples

Convert between JSON and YAML
gofc -f j -f y < input.json > output.yml

and

gofc -f j -f y < input.yml > output.json
Render golang template using YAML as input context
gofc -f y -f tpl -a template.tpl < input.tpl > rendered.txt
Process YAML file using jq
gofc -f y -f j < input.yml | jq '.' | gofc -f j -f y

Input Filters

JSON
name = json | j

Parse input data as JSON.

YAML
name = yaml | yml | y

Parse input data as YAML.

Filters

Variable Files
name = varfiles | v

This filter treats input data as map of variable names and files, reads each file as a structure and outputs new map of variables names and read structures.

Example: Merge YAML and JSON files, process with jq

echo '{
    "jsondata": "file.json",
    "yamldata": "file.yml"
}' | gofc -f json -f varfiles -f json | jq '.'

Output:

{
    "var1": //parsed content of file1.json
    "var2": //parsed content of file2.json
}

Output Filters

Tpl
name = tpl | t
args = template file

Renders the template file as golang template using input as template's context.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFC = NewFC()

Functions

This section is empty.

Types

type BaseFilter

type BaseFilter interface {
	Description() string
	// contains filtered or unexported methods
}

type FC

type FC struct {
	InputFilters  map[string]InputFilter
	Filters       map[string]Filter
	OutputFilters map[string]OutputFilter
}

func NewFC

func NewFC() *FC

func (*FC) AddFilter

func (f *FC) AddFilter(filter Filter, names ...string) error

func (*FC) AddInputFilter

func (f *FC) AddInputFilter(filter InputFilter, names ...string) error

func (*FC) AddOutputFilter

func (f *FC) AddOutputFilter(filter OutputFilter, names ...string) error

func (*FC) GetInputFilter

func (f *FC) GetInputFilter(name string) (filter InputFilter, err error)

func (*FC) NewPipeline

func (f *FC) NewPipeline() *Pipeline

type Filter

type Filter interface {
	BaseFilter
	Filter(input interface{}, args ...string) (interface{}, error)
}

type FilterHCL

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

func (FilterHCL) Description

func (FilterHCL) Description() string

func (FilterHCL) Output

func (FilterHCL) Output(out io.Writer, in interface{}, args ...string) error

type FilterJSON

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

func (FilterJSON) Description

func (FilterJSON) Description() string

func (FilterJSON) Input

func (FilterJSON) Input(in io.Reader, out interface{}, args ...string) error

func (FilterJSON) Output

func (FilterJSON) Output(out io.Writer, in interface{}, args ...string) error

type FilterNULL added in v1.0.9

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

func (FilterNULL) Description added in v1.0.9

func (FilterNULL) Description() string

func (FilterNULL) Input added in v1.0.9

func (FilterNULL) Input(in io.Reader, out interface{}, args ...string) error

type FilterTOML added in v1.0.11

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

func (FilterTOML) Description added in v1.0.11

func (FilterTOML) Description() string

func (FilterTOML) Input added in v1.0.11

func (FilterTOML) Input(in io.Reader, out interface{}, args ...string) error

func (FilterTOML) Output added in v1.0.11

func (FilterTOML) Output(out io.Writer, in interface{}, args ...string) error

type FilterTPL

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

func NewFilterTPL added in v1.0.4

func NewFilterTPL() (r *FilterTPL)

func (FilterTPL) Description

func (FilterTPL) Description() string

func (FilterTPL) Output

func (f FilterTPL) Output(output io.Writer, input interface{}, args ...string) error

type FilterVarFiles

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

func (FilterVarFiles) Description

func (FilterVarFiles) Description() string

func (FilterVarFiles) Filter

func (f FilterVarFiles) Filter(input interface{}, args ...string) (interface{}, error)

type FilterYAML

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

func (FilterYAML) Description

func (FilterYAML) Description() string

func (FilterYAML) Input

func (f FilterYAML) Input(in io.Reader, out interface{}, args ...string) error

func (FilterYAML) Output

func (FilterYAML) Output(out io.Writer, in interface{}, args ...string) error

type InputFilter

type InputFilter interface {
	BaseFilter
	Input(input io.Reader, output interface{}, args ...string) error
}

type OutputFilter

type OutputFilter interface {
	BaseFilter
	Output(output io.Writer, input interface{}, args ...string) error
}

type Pipeline

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

func (*Pipeline) AddFilter

func (p *Pipeline) AddFilter(filterName string, args ...string) error

func (*Pipeline) Process

func (p *Pipeline) Process(in io.Reader, out io.Writer) error

func (*Pipeline) SetInputFilter

func (p *Pipeline) SetInputFilter(inputFilter string, args ...string) error

func (*Pipeline) SetOutputFilter

func (p *Pipeline) SetOutputFilter(outputFilter string, args ...string) error

type S3Downloader added in v1.0.8

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

S3Downloader ...

func NewS3Downloader added in v1.0.8

func NewS3Downloader() (*S3Downloader, error)

NewS3Downloader creates new S3Downloader

func (*S3Downloader) DownloadFileVersion added in v1.0.8

func (s *S3Downloader) DownloadFileVersion(bucket, key, version string) (*s3.GetObjectOutput, error)

DownloadFileVersion downloads single file with specific version

func (*S3Downloader) DownloadFilesByPattern added in v1.0.8

func (s *S3Downloader) DownloadFilesByPattern(bucket, pattern string) (map[string]*s3.GetObjectOutput, error)

DownloadFilesByPattern downloads files matching to pattern from bucket. It uses 16 goroutines for parallel downloads.

type TplImport added in v1.0.6

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

func (TplImport) Render added in v1.0.6

func (t TplImport) Render(input interface{}) (string, error)

Notes

Bugs

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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