converter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2015 License: MIT Imports: 16 Imported by: 0

README

converter

✂ multiformat data conversion

Build Status GoDoc Coverage Status

Usage

converter can be used in the CLI as follow:

$ converter --list-filters
Available filters:
- md5
- sha1
- base64-encode
- base64-decode
- base32-encode
- base32-decode
- hex-encode
- hex-decode
- xml-encode
- xml-decode
- json-encode
- json-decode
- toml-encode
- csv-decode
- fetch
- sleep-100ms
- sleep-1s
- sleep-2s
- sleep-5s
- sleep-10s
- sleep-1m
- reverse
- upper
- lower
- split-lines
- to-unix
- parse-ansi-date
- parse-rfc339-date
- parse-rfc822-date
- parse-rfc850-date
- parse-rfc1123-date
- parse-unix-date
- bytes-to-string
- string-to-bytes
- int-to-string
- string-to-int
- string-to-float
- float-to-string
$ echo 'Hello World!' | converter reverse
!dlroW olleH
$ echo 'Hello World!' | converter md5
8ddd8be4b179a529afa5f2ffae4b9858
$ echo 'Hello World!' | converter md5 md5
b87408ae303f7ca8d4834e5ac3143d06
$ echo 'Hello World!' | converter md5 md5 md5
710f24df02eb8e151074364ea23e1a39
$ echo 'Hello World!' | converter reverse md5 upper reverse
26E80BC257BC2EB49316825A8DB8E0C9
$ echo 'Hello World!' | converter reverse md5 upper reverse base64-decode
[219 161 60 208 16 182 231 176 66 216 64 120 247 125 122 243 110 64 240 48 124 19 64 189]
$ echo 'Hello World!' | converter reverse md5 upper reverse base64-decode bytes-to-string
ۡ<���B�@x�}z�n@�0|@�

Using as a Golang library

See GoDoc for usage and examples.

Changelog

v1.0.0 (2015-12-02)
  • First release
  • Chaining support
  • Pipe support
  • Basic streaming support
  • Helper to convert a basic converter to streaming converter
  • Automtically detect intermediary converters if needed
  • Available filters:
    • base32-decode
    • base32-encode
    • base64-decode
    • base64-encode
    • bytes-to-string
    • csv-decode
    • fetch
    • float-to-string
    • hex-decode
    • hex-encode
    • int-to-string
    • json-decode
    • json-encode
    • lower
    • md5
    • parse-ansi-date
    • parse-date
    • parse-rfc1123-date
    • parse-rfc339-date
    • parse-rfc822-date
    • parse-rfc850-date
    • parse-unix-date
    • parse-unix-timestamp
    • reverse
    • sha1
    • sleep-100ms
    • sleep-10s
    • sleep-1m
    • sleep-1s
    • sleep-2s
    • sleep-5s
    • split-lines
    • string-to-bytes
    • string-to-float
    • string-to-int
    • time-to-string
    • to-unix
    • toml-encode
    • upper
    • xml-decode
    • xml-encode

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ConvertANSICToTime = DateToTimeConverter(time.ANSIC)
View Source
var ConvertRFC1123ToTime = DateToTimeConverter(time.RFC1123)
View Source
var ConvertRFC3339ToTime = DateToTimeConverter(time.RFC3339)
View Source
var ConvertRFC822ToTime = DateToTimeConverter(time.RFC822)
View Source
var ConvertRFC850ToTime = DateToTimeConverter(time.RFC850)
View Source
var ConvertUnixDateToTime = DateToTimeConverter(time.UnixDate)
View Source
var FiveSecondDelayer = Delayer(5 * time.Second)
View Source
var HundredMillisecondDelayer = Delayer(100 * time.Millisecond)
View Source
var OneMinuteDelayer = Delayer(time.Minute)
View Source
var OneSecondDelayer = Delayer(time.Second)
View Source
var RegisteredConverters []*Converter
View Source
var TenSecondDelayer = Delayer(10 * time.Second)
View Source
var TwoSecondDelayer = Delayer(2 * time.Second)

Functions

func ConvertBase32ToBytes

func ConvertBase32ToBytes(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertBase32ToBytes("NBSWY3DPEB3W64TMMQQQ====", &output)
fmt.Println(output)
Output:

[104 101 108 108 111 32 119 111 114 108 100 33]

func ConvertBase64ToBytes

func ConvertBase64ToBytes(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertBase64ToBytes("aGVsbG8gd29ybGQh", &output)
fmt.Println(output)
Output:

[104 101 108 108 111 32 119 111 114 108 100 33]

func ConvertBytesToBase32

func ConvertBytesToBase32(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertBytesToBase32([]byte("hello world!"), &output)
fmt.Println(output)
Output:

NBSWY3DPEB3W64TMMQQQ====

func ConvertBytesToBase64

func ConvertBytesToBase64(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertBytesToBase64([]byte("hello world!"), &output)
fmt.Println(output)
Output:

aGVsbG8gd29ybGQh

func ConvertBytesToHex

func ConvertBytesToHex(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertBytesToHex([]byte("hello world!"), &output)
fmt.Println(output)
Output:

68656c6c6f20776f726c6421

func ConvertBytesToMd5sum

func ConvertBytesToMd5sum(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertBytesToMd5sum([]byte("hello world!"), &output)
fmt.Println(output)
Output:

fc3ff98e8c6a0d3087d515c0473f8677

func ConvertBytesToSha1sum

func ConvertBytesToSha1sum(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertBytesToSha1sum([]byte("hello world!"), &output)
fmt.Println(output)
Output:

430ce34d020724ed75a196dfc2ad67c77772d169

func ConvertBytesToString

func ConvertBytesToString(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertBytesToString([]byte("hello world!"), &output)
fmt.Println(output)
Output:

hello world!

func ConvertDateToTime

func ConvertDateToTime(in interface{}, out *interface{}) (err error)

func ConvertFloatToString

func ConvertFloatToString(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertFloatToString(3.1415, &output)
fmt.Println(output)
Output:

3.1415

func ConvertHexToBytes

func ConvertHexToBytes(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertHexToBytes("68656c6c6f20776f726c6421", &output)
fmt.Println(output)
Output:

[104 101 108 108 111 32 119 111 114 108 100 33]

func ConvertIntegerToString

func ConvertIntegerToString(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertIntegerToString(int64(1234567890), &output)
fmt.Println(output)
Output:

1234567890

func ConvertJsonToStruct

func ConvertJsonToStruct(in interface{}, out *interface{}) (err error)
Example
var output interface{}
input := []byte(`["Hello",42,3.1415]`)
ConvertJsonToStruct(input, &output)
fmt.Printf("%+v\n", output)
Output:

[Hello 42 3.1415]

func ConvertStringToBytes

func ConvertStringToBytes(in interface{}, out *interface{}) error
Example
var output interface{}
ConvertStringToBytes("hello world!", &output)
fmt.Println(output)
Output:

[104 101 108 108 111 32 119 111 114 108 100 33]

func ConvertStringToCsv

func ConvertStringToCsv(in interface{}, out *interface{}) (err error)
Example
input := `first_name,last_name,username
"Rob","Pike",rob
Ken,Thompson,ken
"Robert","Griesemer","gri"
"Manfred",Touron,moul
`
var output interface{}
ConvertStringToCsv(input, &output)
fmt.Printf("%+v\n", output)
Output:

[[first_name last_name username] [Rob Pike rob] [Ken Thompson ken] [Robert Griesemer gri] [Manfred Touron moul]]

func ConvertStringToFloat

func ConvertStringToFloat(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertStringToFloat("3.1415", &output)
fmt.Println(output)
Output:

3.1415

func ConvertStringToInteger

func ConvertStringToInteger(in interface{}, out *interface{}) (err error)
Example
var output interface{}
ConvertStringToInteger("1234567890", &output)
fmt.Println(output)
Output:

1234567890

func ConvertStructToJson

func ConvertStructToJson(in interface{}, out *interface{}) (err error)
Example
var output interface{}
input := []interface{}{
	"Hello", 42, 3.1415,
}
ConvertStructToJson(input, &output)
fmt.Printf("%s\n", output)
Output:

["Hello",42,3.1415]

func ConvertStructToToml

func ConvertStructToToml(in interface{}, out *interface{}) (err error)
Example
var output interface{}
input := map[string]interface{}{
	"a": "Hello",
	"b": 42,
	"c": 3.1415,
}
ConvertStructToToml(input, &output)
fmt.Printf("%s\n", output)
Output:

a = "Hello"
b = 42
c = 3.1415

func ConvertStructToXml

func ConvertStructToXml(in interface{}, out *interface{}) (err error)
Example
var output interface{}
input := []interface{}{
	"Hello", 42, 3.1415,
}
ConvertStructToXml(input, &output)
fmt.Printf("%s\n", output)
Output:

<string>Hello</string><int>42</int><float64>3.1415</float64>

func ConvertTimeToString

func ConvertTimeToString(in interface{}, out *interface{}) (err error)

func ConvertTimeToUnix

func ConvertTimeToUnix(in interface{}, out *interface{}) (err error)
Example
input := time.Date(1988, time.January, 25, 13, 10, 42, 0, time.UTC)
var output interface{}
ConvertTimeToUnix(input, &output)
fmt.Printf("%+v\n", output.(int64))
Output:

570114642

func ConvertUnixTimestampToTime

func ConvertUnixTimestampToTime(in interface{}, out *interface{}) (err error)

func ConvertXmlToStruct

func ConvertXmlToStruct(in interface{}, out *interface{}) (err error)

func FetchUrlToBytes

func FetchUrlToBytes(in interface{}, out *interface{}) error
Example
input := "http://sapin-as-a-service.appspot.com/?size=3"
var output interface{}
FetchUrlToBytes(input, &output)
fmt.Printf("%+s\n", string(output.([]byte)))
Output:

          *
         ***
        *****
       *******
        *****
       *******
      *********
     ***********
    *************
     ***********
    *************
   ***************
  *****************
 *******************
*********************
         |||
         |||
         |||

func Lowercase

func Lowercase(in interface{}, out *interface{}) (err error)

func RegisterConverter

func RegisterConverter(converter *Converter)

func ReverseString

func ReverseString(in interface{}, out *interface{}) (err error)

func StreamBufferSplitLines

func StreamBufferSplitLines(in chan interface{}) chan interface{}

func Uppercase

func Uppercase(in interface{}, out *interface{}) (err error)

Types

type ConversionFn

type ConversionFn func(interface{}, *interface{}) error

func Chain

func Chain(left ConversionFn, rights ...ConversionFn) ConversionFn

func DateToTimeConverter

func DateToTimeConverter(format string) ConversionFn

func Delayer

func Delayer(duration time.Duration) ConversionFn

func GetTypeConversionFunc

func GetTypeConversionFunc(inType, outType string) ConversionFn

func Pipe

func Pipe(left, right ConversionFn) ConversionFn

type Converter

type Converter struct {
	InputType              string
	OutputType             string
	Name                   string
	ConversionFunc         ConversionFn
	StreamConvFunc         StreamConvFn
	IsDefaultTypeConverter bool
}

func GetConverterByName

func GetConverterByName(name string) (*Converter, error)

func NewConverter

func NewConverter(name string) *Converter

func (*Converter) SetConversionFunc

func (conv *Converter) SetConversionFunc(fn ConversionFn) *Converter

func (*Converter) SetDefaultTypeConverter

func (conv *Converter) SetDefaultTypeConverter() *Converter

func (*Converter) SetStreamConvFunc

func (conv *Converter) SetStreamConvFunc(fn StreamConvFn) *Converter

func (*Converter) SetType

func (conv *Converter) SetType(ioType string) *Converter

func (*Converter) SetTypes

func (conv *Converter) SetTypes(inType, outType string) *Converter

type ConverterChain

type ConverterChain []*Converter

func NewConverterChain

func NewConverterChain(filterNames []string) (ConverterChain, error)

func (*ConverterChain) ConversionFunc

func (chain *ConverterChain) ConversionFunc(inType, outType string) (ConversionFn, error)

func (*ConverterChain) Convert

func (chain *ConverterChain) Convert(input interface{}, output *interface{}) error

type StreamConvFn

type StreamConvFn func(chan interface{}) chan interface{}

func ConversionToStreamConv

func ConversionToStreamConv(conversionFn ConversionFn) StreamConvFn

func StreamChain

func StreamChain(streamFuncs ...StreamConvFn) StreamConvFn

func StreamPipe

func StreamPipe(left, right StreamConvFn) StreamConvFn

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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