forked from hhatto/gocloc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
54 lines (48 loc) · 1.42 KB
/
json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gocloc
// JSONLanguagesResult defines the result of the analysis in JSON format.
type JSONLanguagesResult struct {
Languages []ClocLanguage `json:"languages"`
Total ClocLanguage `json:"total"`
}
// JSONFilesResult defines the result of the analysis(by files) in JSON format.
type JSONFilesResult struct {
Files []ClocFile `json:"files"`
Total ClocLanguage `json:"total"`
}
// NewJSONLanguagesResultFromCloc returns JSONLanguagesResult with default data set.
func NewJSONLanguagesResultFromCloc(total *Language, sortedLanguages Languages) JSONLanguagesResult {
var langs []ClocLanguage
for _, language := range sortedLanguages {
c := ClocLanguage{
Name: language.Name,
FilesCount: int32(len(language.Files)),
Code: language.Code,
Comments: language.Comments,
Blanks: language.Blanks,
}
langs = append(langs, c)
}
t := ClocLanguage{
FilesCount: total.Total,
Code: total.Code,
Comments: total.Comments,
Blanks: total.Blanks,
}
return JSONLanguagesResult{
Languages: langs,
Total: t,
}
}
// NewJSONFilesResultFromCloc returns JSONFilesResult with default data set.
func NewJSONFilesResultFromCloc(total *Language, sortedFiles ClocFiles) JSONFilesResult {
t := ClocLanguage{
FilesCount: total.Total,
Code: total.Code,
Comments: total.Comments,
Blanks: total.Blanks,
}
return JSONFilesResult{
Files: sortedFiles,
Total: t,
}
}