-
Notifications
You must be signed in to change notification settings - Fork 224
/
go.go
58 lines (46 loc) · 1.17 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
50
51
52
53
54
55
56
57
58
package scanner
import (
"fmt"
"github.com/superfly/flyctl/terminal"
"golang.org/x/mod/modfile"
"os"
)
func configureGo(sourceDir string, config *ScannerConfig) (*SourceInfo, error) {
if !checksPass(sourceDir, fileExists("go.mod")) {
return nil, nil
}
s := &SourceInfo{
Files: templates("templates/go"),
Family: "Go",
Port: 8080,
Env: map[string]string{
"PORT": "8080",
},
}
if !absFileExists("go.sum") {
s.SkipDeploy = true
terminal.Warn("no go.sum file found, please adjust your Dockerfile to remove references to go.sum")
}
gomod, parseErr := parseModfile()
version := "1"
if parseErr != nil {
terminal.Warnf("go.mod appears to be invalid, the next deployment may fail: %v", parseErr)
} else if gomod.Go.Version != "" {
version = gomod.Go.Version
}
s.BuildArgs = map[string]string{
"GO_VERSION": version,
}
return s, nil
}
func parseModfile() (*modfile.File, error) {
dat, err := os.ReadFile("go.mod")
if err != nil {
return nil, fmt.Errorf("could not open go.mod: %w", err)
}
f, modErr := modfile.Parse("go.mod", dat, nil)
if modErr != nil {
return nil, fmt.Errorf("could not parse go.mod: %w", modErr)
}
return f, nil
}