-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
92 lines (84 loc) · 2.06 KB
/
main.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
package main
import (
"fmt"
"github.com/hashicorp/go-version"
"github.com/keyval-dev/offsets-tracker/binary"
"github.com/keyval-dev/offsets-tracker/target"
"github.com/keyval-dev/offsets-tracker/writer"
"log"
)
func main() {
minimunGoVersion, err := version.NewConstraint(">= 1.12")
if err != nil {
log.Fatalf("error in parsing version constraint: %v\n", err)
}
stdLibOffsets, err := target.New("go").
FindVersionsBy(target.GoDevFileVersionsStrategy).
DownloadBinaryBy(target.DownloadPreCompiledBinaryFetchStrategy).
VersionConstraint(&minimunGoVersion).
FindOffsets([]*binary.DataMember{
{
StructName: "runtime.g",
Field: "goid",
},
{
StructName: "net/http.Request",
Field: "Method",
},
{
StructName: "net/http.Request",
Field: "URL",
},
{
StructName: "net/http.Request",
Field: "RemoteAddr",
},
{
StructName: "net/http.Request",
Field: "ctx",
},
{
StructName: "net/url.URL",
Field: "Path",
},
})
if err != nil {
log.Fatalf("error while fetching offsets: %v\n", err)
}
grpcOffsets, err := target.New("google.golang.org/grpc").
FindOffsets([]*binary.DataMember{
{
StructName: "google.golang.org/grpc/internal/transport.Stream",
Field: "method",
},
{
StructName: "google.golang.org/grpc/internal/transport.Stream",
Field: "id",
},
{
StructName: "google.golang.org/grpc/internal/transport.Stream",
Field: "ctx",
},
{
StructName: "google.golang.org/grpc.ClientConn",
Field: "target",
},
{
StructName: "golang.org/x/net/http2.MetaHeadersFrame",
Field: "Fields",
},
{
StructName: "golang.org/x/net/http2.FrameHeader",
Field: "StreamID",
},
})
if err != nil {
log.Fatalf("error while fetching offsets: %v\n", err)
}
fmt.Println("Done collecting offsets, writing results to file ...")
err = writer.WriteResults(stdLibOffsets, grpcOffsets)
if err != nil {
log.Fatalf("error while writing results to file: %v\n", err)
}
fmt.Println("Done!")
}