Skip to content

Commit 7f0d731

Browse files
committed
0.0.3 release
1 parent f453d9c commit 7f0d731

17 files changed

+143
-57
lines changed

.travis.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ go:
88

99
os:
1010
- linux
11-
- osx
11+
#- osx
1212

1313
matrix:
1414
allow_failures:
1515
- go: tip
1616
fast_finish: true
1717

18+
install:
19+
- go get -u github.com/alecthomas/gometalinter
20+
- gometalinter --install
21+
1822
script:
23+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./gss/
24+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./plugins/gss/
25+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/gss/
26+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/gss.js/
1927
- cd gss
2028
- go fmt
2129
- cd ./../cmd/gss

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/spatialcurrent/go-simple-serializer.svg)](https://travis-ci.org/spatialcurrent/go-simple-serializer) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-simple-serializer?status.svg)](https://godoc.org/github.com/spatialcurrent/go-simple-serializer)
1+
[![Build Status](https://travis-ci.org/spatialcurrent/go-simple-serializer.svg)](https://travis-ci.org/spatialcurrent/go-simple-serializer) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-simple-serializer)](https://goreportcard.com/report/spatialcurrent/go-simple-serializer) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-simple-serializer?status.svg)](https://godoc.org/github.com/spatialcurrent/go-simple-serializer) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/go-simple-serializer/blob/master/LICENSE)
22

33
# go-simple-serializer
44

@@ -56,6 +56,8 @@ The `Convert`, `Deserialize`, and `Serialize` functions are the core functions t
5656
...
5757
```
5858

59+
See [gss](https://godoc.org/github.com/spatialcurrent/go-simple-serializer/gss) in GoDoc for information on how to use Go API.
60+
5961
**JavaScript**
6062

6163
```html
@@ -102,7 +104,7 @@ The Go function definition defined in `plugins/gss/main.go` uses `*C.char` for a
102104
func Convert(input_string *C.char, input_format *C.char, input_header *C.char, input_comment *C.char, output_format *C.char, output_string **C.char) *C.char
103105
```
104106

105-
For complete patterns for `C`, `C++`, and `Python`, see the `examples`.
107+
For complete patterns for `C`, `C++`, and `Python`, see the `go-simpler-serializer/examples` folder.
106108

107109
# Releases
108110

@@ -140,6 +142,10 @@ The `build_android.sh` script is used to build an [Android Archive](https://deve
140142

141143
The `build_so.sh` script is used to build a Shared Object (`*.go`), which can be called by `C`, `C++`, and `Python` on Linux machines.
142144

145+
**Changing Destination**
146+
147+
The default destination for build artifacts is `go-simple-serializer/bin`, but you can change the destination with a CLI argument. For building on a Chromebook consider saving the artifacts in `/usr/local/go/bin`, e.g., `bash scripts/build_cli.sh /usr/local/go/bin`
148+
143149
# Contributing
144150

145151
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/go-simple-serializer/blob/master/CONTRIBUTING.md) for how to get started.

cmd/gss.js/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222
"honnef.co/go/js/console"
2323
)
2424

25-
var GO_GSS_VERSION = "0.0.2"
26-
2725
func main() {
2826
js.Global.Set("gss", map[string]interface{}{
29-
"version": GO_GSS_VERSION,
27+
"version": gss.VERSION,
3028
"convert": Convert,
3129
})
3230
}

cmd/gss/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/spatialcurrent/go-simple-serializer/gss"
2424
)
2525

26-
var GO_GSS_VERSION = "0.0.2"
2726
var GO_GSS_FORMATS = []string{"csv", "tsv", "hcl", "hcl2", "json", "jsonl", "properties", "toml", "yaml"}
2827

2928
func printUsage() {
@@ -67,7 +66,7 @@ func main() {
6766
}
6867

6968
if version {
70-
fmt.Println(GO_GSS_VERSION)
69+
fmt.Println(gss.VERSION)
7170
os.Exit(0)
7271
}
7372

examples/c/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
build_so:
99
go build -o gss.so -buildmode=c-shared github.com/spatialcurrent/go-simple-serializer/plugins/gss
1010
build_c:
11-
mkdir bin && gcc -o bin/gss_test_c test.c -L. -l:gss.so
11+
mkdir -p bin && gcc -o bin/gss_test_c test.c -L. -l:gss.so
1212
build: build_so build_c
1313
run:
1414
LD_LIBRARY_PATH=. bin/gss_test_c

examples/c/gss_test_c

-8.3 KB
Binary file not shown.

examples/python/test.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# =================================================================
2+
#
3+
# Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
# Released as open source under the MIT License. See LICENSE file.
5+
#
6+
# =================================================================
7+
18
from ctypes import *
29
import sys
310

gss/Convert.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import (
1414
// Convert converts an input_string from the input_format to the output_format and returns an error, if any.
1515
func Convert(input_string string, input_format string, input_header []string, input_comment string, output_format string) (string, error) {
1616

17-
object := NewObject(input_string, input_format)
17+
object, err := NewObject(input_string, input_format)
18+
if err != nil {
19+
return "", errors.Wrap(err, "error creating new object for format "+input_format)
20+
}
1821

1922
if input_format == "bson" || input_format == "json" || input_format == "hcl" || input_format == "hcl2" || input_format == "properties" || input_format == "toml" || input_format == "yaml" {
2023
if output_format == "bson" || output_format == "json" || input_format == "hcl" || input_format == "hcl2" || output_format == "properties" || output_format == "toml" || output_format == "yaml" {

gss/Deserialize.go

+37-4
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,26 @@ func Deserialize(input string, format string, input_header []string, input_comme
148148
} else if format == "json" {
149149
return json.Unmarshal([]byte(input), output)
150150
} else if format == "jsonl" {
151-
switch output.(type) {
151+
152+
//s.Interface()(type)
153+
// reflect.TypeOf(s).Elem()
154+
155+
/*s := reflect.ValueOf(output)
156+
if s.Kind() == reflect.Ptr {
157+
fmt.Println("s.Interface():", s.Interface())
158+
s = reflect.Indirect(s).Elem()
159+
if s.Kind() != reflect.Slice {
160+
return errors.New("Output is not of kind slice.")
161+
}
162+
} else if s.Kind() != reflect.Slice {
163+
return errors.New("Output is not of kind slice.")
164+
}*/
165+
166+
//fmt.Println("reflect.TypeOf(output)", reflect.TypeOf(output))
167+
168+
switch output_slice := output.(type) {
152169
case *[]map[string]string:
153-
output_slice := output.(*[]map[string]string)
170+
//output_slice := s.Interface().(*[]map[string]string)
154171
scanner := bufio.NewScanner(strings.NewReader(input))
155172
scanner.Split(bufio.ScanLines)
156173
for scanner.Scan() {
@@ -165,7 +182,7 @@ func Deserialize(input string, format string, input_header []string, input_comme
165182
}
166183
}
167184
case *[]map[string]interface{}:
168-
output_slice := output.(*[]map[string]interface{})
185+
//output_slice := s.Interface().(*[]map[string]interface{})
169186
scanner := bufio.NewScanner(strings.NewReader(input))
170187
scanner.Split(bufio.ScanLines)
171188
for scanner.Scan() {
@@ -179,8 +196,23 @@ func Deserialize(input string, format string, input_header []string, input_comme
179196
*output_slice = append(*output_slice, obj)
180197
}
181198
}
199+
case []map[string]interface{}:
200+
//output_slice := s.Interface().([]map[string]interface{})
201+
scanner := bufio.NewScanner(strings.NewReader(input))
202+
scanner.Split(bufio.ScanLines)
203+
for scanner.Scan() {
204+
line := strings.TrimSpace(scanner.Text())
205+
if len(input_comment) == 0 || !strings.HasPrefix(line, input_comment) {
206+
obj := map[string]interface{}{}
207+
err := json.Unmarshal([]byte(line), &obj)
208+
if err != nil {
209+
return errors.Wrap(err, "Error reading object from JSON line")
210+
}
211+
output_slice = append(output_slice, obj)
212+
}
213+
}
182214
default:
183-
return errors.New("Cannot deserialize to type " + fmt.Sprint(reflect.ValueOf(output)))
215+
return errors.New("Cannot deserialize to type " + fmt.Sprint(reflect.TypeOf(output).String()))
184216
}
185217
} else if format == "hcl" {
186218
obj, err := hcl.Parse(input)
@@ -202,5 +234,6 @@ func Deserialize(input string, format string, input_header []string, input_comme
202234
} else if format == "yaml" {
203235
return yaml.Unmarshal([]byte(input), output)
204236
}
237+
205238
return nil
206239
}

gss/NewObject.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1+
// =================================================================
2+
//
3+
// Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
// Released as open source under the MIT License. See LICENSE file.
5+
//
6+
// =================================================================
7+
18
package gss
29

310
import (
411
"strings"
512
"unicode"
613
)
714

8-
func NewObject(content string, format string) interface{} {
15+
func NewObject(content string, format string) (interface{}, error) {
16+
917
if format == "json" {
1018
content = strings.TrimLeftFunc(content, unicode.IsSpace)
1119
if len(content) > 0 && content[0] == '[' {
12-
return []map[string]interface{}{}
20+
return []map[string]interface{}{}, nil
1321
}
14-
return map[string]interface{}{}
22+
return map[string]interface{}{}, nil
1523
} else if format == "yaml" {
1624
content = strings.TrimLeftFunc(content, unicode.IsSpace)
1725
if len(content) > 0 && content[0] == '-' {
18-
return []map[string]interface{}{}
26+
return []map[string]interface{}{}, nil
1927
}
20-
return map[string]interface{}{}
28+
return map[string]interface{}{}, nil
2129
} else if format == "bson" || format == "hcl" || format == "hcl2" || format == "properties" || format == "toml" {
22-
return map[string]interface{}{}
30+
return map[string]interface{}{}, nil
31+
} else if format == "jsonl" || format == "csv" || format == "tsv" {
32+
return []map[string]interface{}{}, nil
2333
}
2434

25-
return nil
35+
return nil, nil
2636
}

gss/StringifyMapKeys.go

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ func StringifyMapKeys(in interface{}) interface{} {
3434
res[k] = StringifyMapKeys(v)
3535
}
3636
return res
37+
case map[interface{}]struct{}:
38+
res := make(map[string]interface{})
39+
for k, v := range in {
40+
res[fmt.Sprintf("%v", k)] = StringifyMapKeys(v)
41+
}
42+
return res
3743
default:
3844
return in
3945
}

gss/Version.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// =================================================================
2+
//
3+
// Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
// Released as open source under the MIT License. See LICENSE file.
5+
//
6+
// =================================================================
7+
8+
package gss
9+
10+
var VERSION = "0.0.3"

plugins/gss/main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
package main
1212

1313
import (
14-
"C"
15-
"strings"
14+
"C"
15+
"strings"
1616
)
1717

1818
import (
@@ -27,16 +27,16 @@ func main() {}
2727
func Convert(input_string *C.char, input_format *C.char, input_header *C.char, input_comment *C.char, output_format *C.char, output_string **C.char) *C.char {
2828

2929
s, err := gss.Convert(
30-
C.GoString(input_string),
31-
C.GoString(input_format),
32-
strings.Split(C.GoString(input_header), ","),
33-
C.GoString(input_comment),
34-
C.GoString(output_format))
30+
C.GoString(input_string),
31+
C.GoString(input_format),
32+
strings.Split(C.GoString(input_header), ","),
33+
C.GoString(input_comment),
34+
C.GoString(output_format))
3535
if err != nil {
3636
return C.CString(err.Error())
3737
}
3838

39-
*output_string = C.CString(s)
39+
*output_string = C.CString(s)
4040

41-
return nil
41+
return nil
4242
}

scripts/build_android.sh

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
#!/bin/bash
22

33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
DEST=$(realpath ${1:-$DIR/../bin})
45

5-
mkdir -p $DIR/../bin
6+
mkdir -p $DEST
67

78
echo "******************"
8-
echo "Formatting $DIR/gss"
9+
echo "Formatting $(realpath $DIR/../gss)"
910
cd $DIR/../gss
1011
go fmt
11-
echo "Formatting $DIR/../cmd/gss"
12-
cd $DIR/../cmd/gss
13-
go fmt
1412
echo "Done formatting."
1513
echo "******************"
1614
echo "Building AAR for GSS"
17-
cd $DIR/../bin
15+
cd $DEST
1816
gomobile bind -target android -javapkg=com.spatialcurrent -o gss.aar github.com/spatialcurrent/go-simple-serializer/gss
1917
if [[ "$?" != 0 ]] ; then
2018
echo "Error building AAR for Android"
2119
exit 1
2220
fi
23-
echo "Executable built at $(realpath $DIR/../bin)"
21+
echo "AAR built at $DEST"

scripts/build_cli.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#!/bin/bash
22

33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
DEST=$(realpath ${1:-$DIR/../bin})
45

5-
mkdir -p $DIR/../bin
6+
mkdir -p $DEST
67

78
echo "******************"
8-
echo "Formatting $DIR/gss"
9+
echo "Formatting $(realpath $DIR/../gss)"
910
cd $DIR/../gss
1011
go fmt
11-
echo "Formatting $DIR/../cmd/gss"
12+
echo "Formatting $(realpath $DIR/../cmd/gss)"
1213
cd $DIR/../cmd/gss
1314
go fmt
1415
echo "Done formatting."
1516
echo "******************"
1617
echo "Building program gss"
17-
cd $DIR/../bin
18+
cd $DEST
1819
####################################################
1920
#echo "Building program for darwin"
2021
#GOTAGS= CGO_ENABLED=1 GOOS=${GOOS} GOARCH=amd64 go build --tags "darwin" -o "gss_darwin_amd64" github.com/spatialcurrent/go-simple-serializer/cmd/gss
@@ -24,18 +25,18 @@ cd $DIR/../bin
2425
#fi
2526
#echo "Executable built at $(realpath $DIR/../bin/gss_darwin_amd64)"
2627
####################################################
27-
echo "Building program for linux"
28+
echo "Building program for Linux"
2829
GOTAGS= CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build --tags "linux" -o "gss_linux_amd64" github.com/spatialcurrent/go-simple-serializer/cmd/gss
2930
if [[ "$?" != 0 ]] ; then
3031
echo "Error building gss for Linux"
3132
exit 1
3233
fi
33-
echo "Executable built at $(realpath $DIR/../bin/gss_linux_amd64)"
34+
echo "Executable built at $DEST"
3435
####################################################
3536
echo "Building program for Windows"
3637
GOTAGS= CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build -o "gss_windows_amd64.exe" github.com/spatialcurrent/go-simple-serializer/cmd/gss
3738
if [[ "$?" != 0 ]] ; then
3839
echo "Error building gss for Windows"
3940
exit 1
4041
fi
41-
echo "Executable built at $(realpath $DIR/../bin/gss_windows_amd64.exe)"
42+
echo "Executable built at $DEST"

0 commit comments

Comments
 (0)