Skip to content

Commit 0bd0bb4

Browse files
authored
Merge pull request #43 from jehiah/updates_43
travis->github actions
2 parents b086240 + 365302e commit 0bd0bb4

File tree

8 files changed

+85
-41
lines changed

8 files changed

+85
-41
lines changed

.github/workflows/ci.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
ci:
11+
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v6
18+
with:
19+
go-version: stable
20+
21+
- name: Test
22+
run: go test -timeout 60s -v ./...
23+
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v9
26+
with:
27+
version: latest

.github/workflows/release.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
release:
3+
types: [created]
4+
5+
permissions:
6+
contents: write
7+
packages: write
8+
9+
jobs:
10+
release-go-binary:
11+
name: release Go Binary
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
goos: [linux, darwin]
16+
goarch: [amd64, arm64]
17+
steps:
18+
- uses: actions/checkout@v6
19+
- uses: wangyoucao577/go-release-action@v1
20+
with:
21+
github_token: ${{ secrets.GITHUB_TOKEN }}
22+
goos: ${{ matrix.goos }}
23+
goarch: ${{ matrix.goarch }}

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ json2csv
33

44
Converts a stream of newline separated json data to csv format.
55

6-
[![Build Status](https://travis-ci.org/jehiah/json2csv.png?branch=master)](https://travis-ci.org/jehiah/json2csv) [![GitHub release](https://img.shields.io/github/release/jehiah/json2csv.svg)](https://github.com/jehiah/json2csv/releases/latest)
6+
![Build Status](https://github.com/jehiah/json2csv/actions/workflows/ci.yaml/badge.svg?branch=master)
7+
[![GitHub release](https://img.shields.io/github/release/jehiah/json2csv.svg)](https://github.com/jehiah/json2csv/releases/latest)
78

89

910
Installation

go.mod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module github.com/jehiah/json2csv
22

3-
go 1.13
3+
go 1.20
44

5-
require github.com/stretchr/testify v1.4.0
5+
require github.com/stretchr/testify v1.11.1
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
7-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
5+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
6+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
87
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
98
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
11-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ func get_value(data map[string]interface{}, keyparts []string) string {
6969
subdata, _ := data[keyparts[0]].(map[string]interface{})
7070
return get_value(subdata, keyparts[1:])
7171
} else if v, ok := data[keyparts[0]]; ok {
72-
switch v.(type) {
72+
switch v := v.(type) {
7373
case nil:
7474
return ""
7575
case float64:
76-
f, _ := v.(float64)
77-
if math.Mod(f, 1.0) == 0.0 {
78-
return fmt.Sprintf("%d", int(f))
76+
if math.Mod(v, 1.0) == 0.0 {
77+
return fmt.Sprintf("%d", int(v))
7978
} else {
80-
return fmt.Sprintf("%f", f)
79+
return fmt.Sprintf("%f", v)
8180
}
8281
default:
8382
return fmt.Sprintf("%+v", v)
@@ -114,7 +113,11 @@ func json2csv(r LineReader, w *csv.Writer, keys []string, printHeader bool) {
114113
}
115114

116115
if printHeader {
117-
w.Write(keys)
116+
err = w.Write(keys)
117+
if err != nil {
118+
log.Printf("ERROR Writing header: %s", err)
119+
break
120+
}
118121
w.Flush()
119122
printHeader = false
120123
}
@@ -131,7 +134,16 @@ func json2csv(r LineReader, w *csv.Writer, keys []string, printHeader bool) {
131134
record = append(record, get_value(data, expanded_key))
132135
}
133136

134-
w.Write(record)
137+
err = w.Write(record)
138+
if err != nil {
139+
log.Printf("ERROR Writing record: %s", err)
140+
break
141+
}
135142
w.Flush()
143+
err = w.Error()
144+
if err != nil {
145+
log.Printf("ERROR Flushing record: %s", err)
146+
break
147+
}
136148
}
137149
}

main_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ package main
33
import (
44
"bytes"
55
"encoding/csv"
6-
"io/ioutil"
7-
"log"
8-
"os"
96
"testing"
107

118
"github.com/stretchr/testify/assert"
129
)
1310

1411
func TestGetTopic(t *testing.T) {
15-
log.SetOutput(ioutil.Discard)
16-
defer log.SetOutput(os.Stdout)
17-
1812
reader := bytes.NewBufferString(`{"a": 1, "b": "asdf\n"}
1913
{"a" : null}`)
2014
buf := bytes.NewBuffer([]byte{})
@@ -27,9 +21,6 @@ func TestGetTopic(t *testing.T) {
2721
}
2822

2923
func TestGetLargeInt(t *testing.T) {
30-
log.SetOutput(ioutil.Discard)
31-
defer log.SetOutput(os.Stdout)
32-
3324
reader := bytes.NewBufferString(`{"a": 1356998399}`)
3425
buf := bytes.NewBuffer([]byte{})
3526
writer := csv.NewWriter(buf)
@@ -41,8 +32,6 @@ func TestGetLargeInt(t *testing.T) {
4132
}
4233

4334
func TestGetFloat(t *testing.T) {
44-
log.SetOutput(ioutil.Discard)
45-
defer log.SetOutput(os.Stdout)
4635

4736
reader := bytes.NewBufferString(`{"a": 1356998399.32}`)
4837
buf := bytes.NewBuffer([]byte{})
@@ -55,9 +44,6 @@ func TestGetFloat(t *testing.T) {
5544
}
5645

5746
func TestGetNested(t *testing.T) {
58-
log.SetOutput(ioutil.Discard)
59-
defer log.SetOutput(os.Stdout)
60-
6147
reader := bytes.NewBufferString(`{"a": {"b": "asdf"}}`)
6248
buf := bytes.NewBuffer([]byte{})
6349
writer := csv.NewWriter(buf)
@@ -69,9 +55,6 @@ func TestGetNested(t *testing.T) {
6955
}
7056

7157
func TestHeader(t *testing.T) {
72-
log.SetOutput(ioutil.Discard)
73-
defer log.SetOutput(os.Stdout)
74-
7558
reader := bytes.NewBufferString(`{"a": "b"}
7659
{"a": "c"}`)
7760
buf := bytes.NewBuffer([]byte{})

0 commit comments

Comments
 (0)