forked from hashicorp/otto
/
customization.go
52 lines (42 loc) · 1.33 KB
/
customization.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
package goapp
import (
"fmt"
"github.com/hashicorp/otto/helper/compile"
"github.com/hashicorp/otto/helper/schema"
)
type customizations struct {
Opts *compile.AppOptions
}
func (c *customizations) processDevDep(d *schema.FieldData) error {
cmd, err := c.Opts.Bindata.RenderString(d.Get("run_command").(string))
if err != nil {
return fmt.Errorf("Error processing 'run_command': %s", err)
}
c.Opts.Bindata.Context["dep_run_command"] = cmd
return nil
}
func (c *customizations) processGo(d *schema.FieldData) error {
c.Opts.Bindata.Context["dev_go_version"] = d.Get("go_version")
// Go is really finicky about the GOPATH. To help make the dev
// environment and build environment more correct, we attempt to
// detect the GOPATH automatically.
//
// We use this GOPATH for example in Vagrant to setup the synced
// folder directly into the GOPATH properly. Magic!
gopathPath := d.Get("import_path").(string)
if gopathPath == "" {
var err error
c.Opts.Ctx.Ui.Header("Detecting application import path for GOPATH...")
gopathPath, err = detectImportPath(c.Opts.Ctx)
if err != nil {
return err
}
}
folderPath := "/vagrant"
if gopathPath != "" {
folderPath = "/opt/gopath/src/" + gopathPath
}
c.Opts.Bindata.Context["import_path"] = gopathPath
c.Opts.Bindata.Context["shared_folder_path"] = folderPath
return nil
}