-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt.go
97 lines (84 loc) · 2.17 KB
/
fmt.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"sort"
"strings"
)
func (fd FuncDecl) String() string {
return fmt.Sprintf("`%s`", fd.Name)
}
func (sd StructDecl) String() string {
return fmt.Sprintf("`%s`", sd.Name)
}
func (fds FuncDecls) String() string {
str := ""
for index, fd := range fds {
str += fmt.Sprintf("%d. [%s](%s): %s\n", index+1, fd, fd.Pos.String(), fd.Description)
}
return str
}
func (sds StructDecls) String() string {
str := ""
index := 1
var structSlice []StructDecl
for _, sd := range sds {
structSlice = append(structSlice, sd)
}
sort.Slice(structSlice, func(i, j int) bool { return structSlice[i].Name < structSlice[j].Name })
for _, sd := range structSlice {
str += fmt.Sprintf("%d. [%s](%s): %s\n\n", index, sd, sd.Pos.String(), sd.Description)
if sd.FuncDecls != nil {
str += "\tMethods:\n"
}
sort.Slice(sd.FuncDecls, func(i, j int) bool { return sd.FuncDecls[i].Name < sd.FuncDecls[j].Name })
for i, f := range sd.FuncDecls {
str += fmt.Sprintf("\t%d. [%s](%s): %s\n", i+1, f, f.Pos.String(), f.Description)
}
index++
}
return str
}
func (pkg Package) String() string {
str := fmt.Sprintf(`<details>
<summary> <strong> %s </strong> </summary>
---
`, pkg.Name)
if pkg.Description != "" {
str += fmt.Sprintf(`##### %s
`, pkg.Description)
str += "\n---\n"
}
sort.Slice(pkg.FuncDecls, func(i, j int) bool { return pkg.FuncDecls[i].Name < pkg.FuncDecls[j].Name })
if pkg.FuncDecls != nil {
str += `##### Functions:
`
str += fmt.Sprint(pkg.FuncDecls)
str += "\n---\n"
}
if len(pkg.StructDecls) != 0 {
str += `##### Types
`
str += fmt.Sprint(pkg.StructDecls)
str += "\n---\n"
}
str += "</details>"
return str
}
func (pkgs Packages) String() string {
var str string = "# Packages:\n\n"
var pkgSlice []Package
for _, pkg := range pkgs {
pkgSlice = append(pkgSlice, pkg)
}
sort.Slice(pkgSlice, func(i, j int) bool { return pkgSlice[i].Name < pkgSlice[j].Name })
for _, pkg := range pkgSlice {
if len(pkg.FuncDecls) != 0 || len(pkg.StructDecls) != 0 {
str += fmt.Sprint(pkg)
}
}
return str
}
func (p *Pos) String() string {
str := fmt.Sprintf("%s#L%d", strings.Replace(p.FileName, sourcePath, ".", 1), p.Line)
return str
}