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 55 56 57 58 59 60 61 62 63
|
package main
import (
"fmt"
"go/ast"
"regexp"
)
func getPackageItem(packageName string, files map[string]*ast.File) (jewelryItem, error) {
docRe := regexp.MustCompile(`.*/doc.go`)
for k, f := range files {
matched := docRe.Match([]byte(k))
if !matched {
continue
}
return jewelryItem{
Tags: []string{},
OtherBlocks: map[string]string{},
Members: []jewelryItem{},
Params: []jewelryParam{},
BreadCrumbs: []breadCrumb{},
Summary: formatComment(f.Doc),
}, nil
}
return jewelryItem{}, fmt.Errorf("no doc.go")
}
func hasDocFile(p *ast.Package) bool {
docRe := regexp.MustCompile(`.*/doc.go`)
for k := range p.Files {
matched := docRe.Match([]byte(k))
if !matched {
continue
}
return true
}
return false
}
func isExported(name string) bool {
if name == "" {
return false
}
firstChar := name[0]
if firstChar >= 'a' && firstChar <= 'z' {
return false
}
return true
}
func removeTestFiles(files map[string]*ast.File) error {
testRe := regexp.MustCompile(`.*_test.go`)
for key := range files {
matched := testRe.Match([]byte(key))
if !matched {
continue
}
delete(files, key)
}
return nil
}
|