Skip to content

Commit df0cdf8

Browse files
Use camelCase for json prooperties
Signed-off-by: Rohit Nayak <[email protected]>
1 parent de16070 commit df0cdf8

File tree

3 files changed

+39
-44
lines changed

3 files changed

+39
-44
lines changed

go/schema/schema.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ func run(out io.Writer, cfg Config) error {
4848
}
4949

5050
type TableInfo struct {
51-
Name string
52-
Rows int
51+
Name string `json:"name"`
52+
Rows int `json:"rows"`
5353
}
5454

5555
type Info struct {
56-
Tables []TableInfo
56+
FileType string `json:"fileType"`
57+
Tables []TableInfo `json:"tables"`
5758
}
5859

5960
func Get(cfg Config) (*Info, error) {

go/summarize/utils.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ var fileTypeMap = map[string]fileType{
4141
// getFileType reads the first key-value pair from a JSON file and returns the type of the file
4242
// Note:
4343
func getFileType(filename string) (fileType, error) {
44-
// read json file
4544
file, err := os.Open(filename)
4645
if err != nil {
4746
return unknownFile, errors.New(fmt.Sprintf("error opening file: %v", err))
@@ -55,14 +54,11 @@ func getFileType(filename string) (fileType, error) {
5554
return unknownFile, errors.New(fmt.Sprintf("Error reading token: %v", err))
5655
}
5756

58-
// Ensure the token is the start of an object
5957
if delim, ok := token.(json.Delim); !ok || delim != '{' {
6058
return unknownFile, errors.New(fmt.Sprintf("Expected start of object '{'"))
6159
}
6260

63-
// Read the key-value pairs
6461
for decoder.More() {
65-
// Read the key
6662
keyToken, err := decoder.Token()
6763
if err != nil {
6864
return unknownFile, errors.New(fmt.Sprintf("Error reading key token: %v", err))
@@ -73,14 +69,12 @@ func getFileType(filename string) (fileType, error) {
7369
return unknownFile, errors.New(fmt.Sprintf("Expected key to be a string: %s", keyToken))
7470
}
7571

76-
// Read the value
7772
valueToken, err := decoder.Token()
7873
if err != nil {
7974
return unknownFile, errors.New(fmt.Sprintf("Error reading value token: %v", err))
8075
}
8176

82-
// Check if the key is "FileType"
83-
if key == "FileType" {
77+
if key == "fileType" {
8478
if fileType, ok := fileTypeMap[valueToken.(string)]; ok {
8579
return fileType, nil
8680
} else {

go/testdata/sakila-schema-info.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
{
2-
"FileType": "dbinfo",
3-
"Tables": [
2+
"fileType": "dbinfo",
3+
"tables": [
44
{
5-
"Name": "actor",
6-
"Rows": 200
5+
"name": "actor",
6+
"rows": 200
77
},
88
{
9-
"Name": "address",
10-
"Rows": 603
9+
"name": "address",
10+
"rows": 603
1111
},
1212
{
13-
"Name": "category",
14-
"Rows": 16
13+
"name": "category",
14+
"rows": 16
1515
},
1616
{
17-
"Name": "city",
18-
"Rows": 600
17+
"name": "city",
18+
"rows": 600
1919
},
2020
{
21-
"Name": "country",
22-
"Rows": 109
21+
"name": "country",
22+
"rows": 109
2323
},
2424
{
25-
"Name": "customer",
26-
"Rows": 599
25+
"name": "customer",
26+
"rows": 599
2727
},
2828
{
29-
"Name": "film",
30-
"Rows": 1000
29+
"name": "film",
30+
"rows": 1000
3131
},
3232
{
33-
"Name": "film_actor",
34-
"Rows": 5462
33+
"name": "film_actor",
34+
"rows": 5462
3535
},
3636
{
37-
"Name": "film_category",
38-
"Rows": 1000
37+
"name": "film_category",
38+
"rows": 1000
3939
},
4040
{
41-
"Name": "film_text",
42-
"Rows": 1000
41+
"name": "film_text",
42+
"rows": 1000
4343
},
4444
{
45-
"Name": "inventory",
46-
"Rows": 4581
45+
"name": "inventory",
46+
"rows": 4581
4747
},
4848
{
49-
"Name": "language",
50-
"Rows": 6
49+
"name": "language",
50+
"rows": 6
5151
},
5252
{
53-
"Name": "payment",
54-
"Rows": 16086
53+
"name": "payment",
54+
"rows": 16086
5555
},
5656
{
57-
"Name": "rental",
58-
"Rows": 15425
57+
"name": "rental",
58+
"rows": 15425
5959
},
6060
{
61-
"Name": "staff",
62-
"Rows": 2
61+
"name": "staff",
62+
"rows": 2
6363
},
6464
{
65-
"Name": "store",
66-
"Rows": 2
65+
"name": "store",
66+
"rows": 2
6767
}
6868
]
6969
}

0 commit comments

Comments
 (0)