-
Notifications
You must be signed in to change notification settings - Fork 35
/
go.go
49 lines (43 loc) · 1.47 KB
/
go.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
package sdk
import (
"fmt"
"github.com/viant/endly"
"github.com/viant/endly/service/deployment/deploy"
"github.com/viant/endly/internal/util"
"github.com/viant/endly/model"
"github.com/viant/endly/service/system/exec"
"path"
)
// TODO complete implementation
type goService struct{}
func (s *goService) setSdk(context *endly.Context, request *SetRequest) (*Info, error) {
var result = &Info{}
var sdkHome = path.Join(request.BaseLocation, "go")
var runResponse = &exec.RunResponse{}
setGoROOT := exec.NewRunRequest(request.Target, false, fmt.Sprintf("export GOROOT='%v'", sdkHome))
_ = endly.Run(context, setGoROOT, nil)
var extractRequest = exec.NewExtractRequest(request.Target, exec.DefaultOptions(),
exec.NewExtractCommand("go version", "", nil, nil,
model.NewExtract("version", "go version go([^\\s]+)", false, false)),
)
extractRequest.SystemPaths = append(extractRequest.SystemPaths, fmt.Sprintf("%v/bin", sdkHome))
if err := endly.Run(context, extractRequest, runResponse); err != nil {
return nil, err
}
var stdout = runResponse.Stdout()
if util.CheckCommandNotFound(stdout) || util.CheckNoSuchFileOrDirectory(stdout) {
return nil, errSdkNotFound
}
result.Sdk = "go"
result.Home = sdkHome
if version, ok := runResponse.Data["version"]; ok {
result.Version = version.(string)
}
if !deploy.MatchVersion(request.Version, result.Version) {
return nil, errSdkNotFound
}
if result.Version == "" {
result.Version = request.Version
}
return result, nil
}