@@ -25,6 +25,7 @@ import (
25
25
"os"
26
26
"os/exec"
27
27
"path/filepath"
28
+ "regexp"
28
29
"strings"
29
30
30
31
"github.com/apache/skywalking-go/tools/go-agent/tools"
@@ -33,16 +34,23 @@ import (
33
34
"github.com/dave/dst/decorator"
34
35
)
35
36
36
- var projectBaseImportPath = "github.com/apache/skywalking-go"
37
- var goModFileName = "go.mod"
37
+ const (
38
+ projectBaseImportPath = "github.com/apache/skywalking-go"
39
+ goModFileName = "go.mod"
38
40
39
- var swImportFileName = "skywalking_inject.go"
40
- var swImportFileContent = fmt .Sprintf (`// Code generated by skywalking-go-agent. DO NOT EDIT.
41
+ swImportFileName = "skywalking_inject.go"
42
+ )
43
+
44
+ var (
45
+ swImportFileContent = fmt .Sprintf (`// Code generated by skywalking-go-agent. DO NOT EDIT.
41
46
42
47
package main
43
48
44
49
import _ "%s"` , projectBaseImportPath )
45
50
51
+ gitSHARegex = regexp .MustCompile (`^[0-9a-fA-F]{40}$|^[0-9a-fA-F]{7}$` )
52
+ )
53
+
46
54
type projectInjector struct {
47
55
}
48
56
@@ -133,8 +141,12 @@ func (i *projectInjector) findGoModFileInDir(dir string) bool {
133
141
}
134
142
135
143
func (i * projectInjector ) injectLibraryInRoot (dir string ) error {
136
- fmt .Printf ("injecting skywalking-go@v%s depenedency into %s\n " , version , dir )
137
- command := exec .Command ("go" , "get" , "github.com/apache/skywalking-go@v" + version )
144
+ v := version
145
+ if ! gitSHARegex .MatchString (version ) {
146
+ v = "v" + version
147
+ }
148
+ fmt .Printf ("injecting skywalking-go@%s depenedency into %s\n " , v , dir )
149
+ command := exec .Command ("go" , "get" , "github.com/apache/skywalking-go@" + v )
138
150
command .Dir = dir
139
151
command .Stdin = os .Stdin
140
152
command .Stdout = os .Stdout
0 commit comments