-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreporting.go
41 lines (34 loc) · 1016 Bytes
/
reporting.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
package main
import (
"fmt"
"log"
"os"
"path/filepath"
)
type Reporting interface{ ReportVanished(info VanishedInfo) }
type LogReporting struct{}
func (_ LogReporting) ReportVanished(info VanishedInfo) {
snippet := ""
f, err := os.OpenFile(info.Filename(), os.O_RDONLY, os.ModePerm)
if err != nil {
panic(err)
}
start, end := info.StartLineOffsets()
_, _ = f.Seek(int64(start), 0)
buffer := make([]byte, end-start)
_, _ = f.Read(buffer)
snippet = string(buffer)
log.Printf(
"it seems like your code vanished from compiled binary: func=[%v], file=[%v], lines=[%v-%v], snippet:\n\t%v",
info.FuncName,
info.Filename(),
info.StartLine(),
info.EndLine(),
snippet,
)
}
type GitHubReporting struct{}
func (_ GitHubReporting) ReportVanished(info VanishedInfo) {
relativePath, _ := filepath.Rel(info.AnalysisPath, info.Filename())
fmt.Printf("::warning file=%v,line=%v,endLine=%v::%v\n", relativePath, info.StartLine(), info.EndLine(), "seems like code vanished from compiled binary")
}