Skip to content

Commit 4b031ea

Browse files
committed
0.0.4 release
1 parent d08731a commit 4b031ea

5 files changed

Lines changed: 28 additions & 21 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
- [go-simple-serializer](https://github.com/spatialcurrent/go-simple-serializer) (GSS) for reading/writing objects to standard formats, and
1010
- [go-dfl](https://github.com/spatialcurrent/go-dfl) for filtering and transforming data.
1111

12+
**Railgun** uses the **Dynamic Filter Language** through **go-dfl**. See the `*_test` files in the [dfl](https://github.com/spatialcurrent/go-dfl/tree/master/dfl) source folder on GitHub for comprehensive examples of the syntax.
13+
1214
go-reader can read from `stdin`, `http/https`, the local filesystem, [AWS S3](https://aws.amazon.com/s3/), and [HDFS](https://hortonworks.com/apache/hdfs/).
1315

1416
go-simple-serializer (GSS) supports `bson`, `csv`, `tsv`, `hcl`, `hcl2`, `json`, `jsonl`, `properties`, `toml`, `yaml`. `hcl` and `hcl2` implementation is fragile and very much in `alpha`.
1517

18+
For an interactive demo, see the [railgun notebook](https://beta.observablehq.com/@pjdufour/railgun) on [ObservableHQ](http://observablehq.com). It is very heavy, so only use WiFi.
19+
1620
# Usage
1721

1822
**CLI**

cmd/railgun.js/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// =================================================================
77

8-
// railgun.js is the Javascript version of Railgun.
8+
// railgun.js is the Javascript package for Railgun.
99
//
1010
package main
1111

@@ -20,10 +20,10 @@ import (
2020
)
2121

2222
import (
23-
dfljs "github.com/spatialcurrent/go-dfl/cmd/dfl.js"
2423
"github.com/spatialcurrent/go-dfl/dfl"
25-
gssjs "github.com/spatialcurrent/go-simple-serializer/cmd/gss.js"
24+
"github.com/spatialcurrent/go-dfl/dfljs"
2625
"github.com/spatialcurrent/go-simple-serializer/gss"
26+
"github.com/spatialcurrent/go-simple-serializer/gssjs"
2727
"github.com/spatialcurrent/railgun/railgun"
2828
)
2929

@@ -32,9 +32,6 @@ import (
3232
"honnef.co/go/js/console"
3333
)
3434

35-
var GO_RAILGUN_COMPRESSION_ALGORITHMS = []string{"none", "gzip", "snappy"}
36-
var GO_RAILGUN_FORMATS = []string{"csv", "tsv", "hcl", "hcl2", "json", "jsonl", "properties", "toml", "yaml"}
37-
3835
func main() {
3936

4037
js.Global.Set("railgun", map[string]interface{}{
@@ -49,8 +46,11 @@ func main() {
4946
"EvaluateString": dfljs.EvaluateString,
5047
},
5148
"gss": map[string]interface{}{
52-
"version": gss.VERSION,
53-
"convert": gssjs.Convert,
49+
"version": gss.VERSION,
50+
"formats": gss.Formats,
51+
"convert": gssjs.Convert,
52+
"deserialize": gssjs.Deserialize,
53+
"serialize": gssjs.Serialize,
5454
},
5555
})
5656
}
@@ -147,15 +147,15 @@ func Process(in interface{}, options *js.Object) interface{} {
147147
if len(dfl_exp) > 0 {
148148
n, err := dfl.Parse(dfl_exp)
149149
if err != nil {
150-
console.Error(errors.Wrap(err, "Error parsing dfl node.").Error())
150+
console.Error(errors.Wrap(err, "Error parsing DFL node.").Error())
151151
return ""
152152
}
153153
dfl_node = n.Compile()
154154
}
155155

156156
var output interface{}
157157
if dfl_node != nil {
158-
o, err := dfl_node.Evaluate(ctx, dfl.NewFuntionMapWithDefaults(), []string{"\"", "'", "`"})
158+
_, o, err := dfl_node.Evaluate(map[string]interface{}{}, ctx, dfl.NewFuntionMapWithDefaults(), []string{"\"", "'", "`"})
159159
if err != nil {
160160
console.Error(errors.Wrap(err, "error processing").Error())
161161
return ""

cmd/railgun/main.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//
66
// =================================================================
77

8+
// railgun is the command line program for Railgun.
9+
//
810
package main
911

1012
import (
@@ -42,7 +44,6 @@ import (
4244
)
4345

4446
var GO_RAILGUN_COMPRESSION_ALGORITHMS = []string{"none", "bzip2", "gzip", "snappy"}
45-
var GO_RAILGUN_FORMATS = []string{"bson", "csv", "tsv", "hcl", "hcl2", "json", "jsonl", "properties", "toml", "yaml"}
4647
var GO_RAILGUN_DEFAULT_SALT = "4F56C8C88B38CD8CD96BF8A9724F4BFE"
4748

4849
func printUsage() {
@@ -116,19 +117,19 @@ func main() {
116117

117118
flag.StringVar(&input_uri, "input_uri", "stdin", "The input uri")
118119
flag.StringVar(&input_compression, "input_compression", "none", "The input compression: "+strings.Join(GO_RAILGUN_COMPRESSION_ALGORITHMS, ", "))
119-
flag.StringVar(&input_format, "input_format", "", "The input format: "+strings.Join(GO_RAILGUN_FORMATS, ", "))
120+
flag.StringVar(&input_format, "input_format", "", "The input format: "+strings.Join(gss.Formats, ", "))
120121
flag.StringVar(&input_header_text, "h", "", "The input header if the stdin input has no header.")
121122
flag.StringVar(&input_comment, "c", "", "The input comment character, e.g., #. Commented lines are not sent to output.")
122123
flag.StringVar(&input_passphrase_string, "input_passphrase", "", "The input passphrase.")
123-
flag.StringVar(&input_salt_string, "input_salt", GO_RAILGUN_DEFAULT_SALT, "The input salt as hexidecimal.")
124+
flag.StringVar(&input_salt_string, "input_salt", GO_RAILGUN_DEFAULT_SALT, "The input salt as hexadecimal.")
124125

125126
flag.IntVar(&input_reader_buffer_size, "input_reader_buffer_size", 4096, "The input reader buffer size") // default from https://golang.org/src/bufio/bufio.go
126127

127128
flag.StringVar(&output_uri, "output_uri", "stdout", "The output uri")
128129
flag.StringVar(&output_compression, "output_compression", "none", "The output compression: "+strings.Join(GO_RAILGUN_COMPRESSION_ALGORITHMS, ", "))
129-
flag.StringVar(&output_format, "output_format", "", "The output format: "+strings.Join(GO_RAILGUN_FORMATS, ", "))
130+
flag.StringVar(&output_format, "output_format", "", "The output format: "+strings.Join(gss.Formats, ", "))
130131
flag.StringVar(&output_passphrase_string, "output_passphrase", "", "The output passphrase.")
131-
flag.StringVar(&output_salt_string, "output_salt", GO_RAILGUN_DEFAULT_SALT, "The output salt as hexidecimal.")
132+
flag.StringVar(&output_salt_string, "output_salt", GO_RAILGUN_DEFAULT_SALT, "The output salt as hexadecimal.")
132133

133134
flag.StringVar(&dfl_exp, "dfl_exp", "", "Process using dfl expression")
134135
flag.StringVar(&dfl_file, "dfl_file", "", "Process using dfl file.")
@@ -312,23 +313,25 @@ func main() {
312313
log.Fatal(errors.Wrap(err, "error dumping dfl_node as yaml to stdout"))
313314
}
314315
fmt.Println(dfl_node_yaml)
316+
fmt.Println(dfl_node.Dfl(dfl.DefaultQuotes, true, 0))
315317
}
316318

317319
input_type, err := gss.GetType(input_string, input_format)
318320
if err != nil {
319321
log.Fatal(errors.Wrap(err, "error geting type for input"))
320322
}
321-
323+
322324
input_object, err := gss.Deserialize(input_string, input_format, input_header, input_comment, input_type, verbose)
323325
if err != nil {
324326
log.Fatal(errors.Wrap(err, "error deserializing input using format "+input_format))
325327
}
326-
328+
327329
var output interface{}
328330
if dfl_node != nil {
329-
o, err := dfl_node.Evaluate(input_object, funcs, []string{"'", "\"", "`"})
331+
_, o, err := dfl_node.Evaluate(map[string]interface{}{}, input_object, funcs, []string{"'", "\"", "`"})
330332
if err != nil {
331-
log.Fatal(errors.Wrap(err, "error processing"))
333+
fmt.Fprintf(os.Stdout, "%+v", err)
334+
log.Fatal(errors.Wrap(err, "error evaluating filter"))
332335
}
333336
output = o
334337
} else {

railgun/InferFormatAndCompression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"path/filepath"
1212
)
1313

14-
// InferFormatAndCompression infers the format and compresion of the file.
14+
// InferFormatAndCompression infers the format and compression of the file.
1515
// - *.json => ("json", "") // JSON File
1616
// - *.json.bz2 => ("json", "bzip2") // bzip2-compressed JSON file
1717
// - *.json.gz => ("json", "gzip") // gzip-compressed JSON file

railgun/Version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
package railgun
99

10-
var VERSION = "0.0.3"
10+
var VERSION = "0.0.4"

0 commit comments

Comments
 (0)