diff --git a/coverage/reader.go b/coverage/reader.go index 2286676..2ec68e2 100644 --- a/coverage/reader.go +++ b/coverage/reader.go @@ -16,7 +16,7 @@ func Parse(r io.Reader, gopkg string) (*Files, error) { var n uint = 0 files := &Files{ - files: make(map[string]File), + Files: make(map[string]File), packagePath: gopkg, } @@ -104,11 +104,11 @@ func Parse(r io.Reader, gopkg string) (*Files, error) { } // append to files - _, isset := files.files[filename] + _, isset := files.Files[filename] if !isset { - files.files[filename] = make(File, 0) + files.Files[filename] = make(File, 0) } - files.files[filename] = append(files.files[filename], cover) + files.Files[filename] = append(files.Files[filename], cover) } diff --git a/coverage/types.go b/coverage/types.go index a04e36b..103d545 100644 --- a/coverage/types.go +++ b/coverage/types.go @@ -5,7 +5,7 @@ import "strings" // Files contains coverage files indexed by file path type Files struct { packagePath string - files map[string]File + Files map[string]File } // File represents every coverage chunk for a file @@ -20,22 +20,25 @@ type Coverage struct { } // GetFile returns the formatted coverage for the file located at @path -func (f *Files) GetFile(path string) []File { +func (f *Files) GetFile(path string) *Files { var isDir bool = !strings.HasSuffix(path, ".go") - files := make([]File, 0) + files := &Files{ + packagePath: f.packagePath, + Files: make(map[string]File), + } // search in coverage files - for fPath, fileCoverage := range f.files { + for fPath, fileCoverage := range f.Files { if !isDir && path == fPath { - files = append(files, fileCoverage) + files.Files[fPath] = fileCoverage // if not directory search, stop at first result break } if isDir && (path == "." || strings.HasPrefix(fPath, path)) { - files = append(files, fileCoverage) + files.Files[fPath] = fileCoverage } }