Skip to content

Commit 505ffe4

Browse files
author
Vic Shóstak
committed
Add comments for functions
1 parent e234085 commit 505ffe4

File tree

7 files changed

+19
-3
lines changed

7 files changed

+19
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# json2csv – Parse JSON files to CSV with data qualifier
22

3-
![Go version][go_version_img]
3+
[![Go version][go_version_img]][json2csv_go_dev_url]
44
[![Go report][go_report_img]][go_report_url]
55
![Code coverage][code_coverage_img]
66
[![Wiki][wiki_img]][wiki_url]
@@ -97,4 +97,5 @@ robots by [Vic Shóstak][author].
9797
[license_img]: https://img.shields.io/badge/license-Apache_2.0-red?style=for-the-badge&logo=none
9898
[license_url]: https://github.com/koddr/json2csv/blob/main/LICENSE
9999
[json2csv_url]: https://github.com/koddr/json2csv
100+
[json2csv_go_dev_url]: https://pkg.go.dev/github.com/koddr/json2csv
100101
[author]: https://github.com/koddr

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import "os"
44

5+
// config presents struct for the configuration.
56
type config struct {
67
outputFolder string
78
contentField string
@@ -12,6 +13,7 @@ type config struct {
1213
chunkSize int
1314
}
1415

16+
// jsonFolder presents struct for the folder with JSON sources.
1517
type jsonFolder struct {
1618
path string
1719
files []os.DirEntry

filter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
jsoniter "github.com/json-iterator/go"
88
)
99

10+
// filter provides rule sets for the input string to skip specified values.
1011
func (c *config) filter(s string) bool {
1112
// Skip empty strings.
1213
if s == "" {

parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
jsoniter "github.com/json-iterator/go"
1010
)
1111

12+
// parse provides the parsing process.
1213
func (c *config) parse() error {
1314
// Create slice for results.
1415
results := make([]map[string]string, 0, len(c.jsonFolder.files))

qualifier.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
jsoniter "github.com/json-iterator/go"
88
)
99

10+
// qualify provides a qualifier for the given string.
1011
func (c *config) qualify(s string) string {
1112
// Skip empty strings.
1213
if s == "" {

save_to_csv.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import (
77
"time"
88
)
99

10+
// save provides saving operation for source map.
1011
func (c *config) save(source []map[string]string) error {
1112
// Create a new file to collect CSV data.
1213
outputFile, err := os.Create(fmt.Sprintf("%s/%d.csv", c.outputFolder, time.Now().Unix()))
1314
if err != nil {
1415
return err
1516
}
16-
defer outputFile.Close()
17+
defer func(outputFile *os.File) {
18+
err := outputFile.Close()
19+
if err != nil {
20+
21+
}
22+
}(outputFile)
1723

1824
// Write the header of the CSV file and the successive rows by iterating through
1925
// the JSON struct array.

session.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
"path/filepath"
77
)
88

9-
func newSession(jsonPath, intentsPath, filterPath, outputPath, contentField string, minWordLen, chunkSize int) (*config, error) {
9+
// newSession provides init configuration for the parsing session.
10+
func newSession(
11+
jsonPath, intentsPath, filterPath, outputPath, contentField string,
12+
minWordLen, chunkSize int,
13+
) (*config, error) {
1014
if minWordLen < 0 {
1115
return nil, errors.New("can't parse data with negative word count")
1216
}

0 commit comments

Comments
 (0)