github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/app/go/customization.go (about)

     1  package goapp
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/otto/helper/compile"
     7  	"github.com/hashicorp/otto/helper/schema"
     8  )
     9  
    10  type customizations struct {
    11  	Opts *compile.AppOptions
    12  }
    13  
    14  func (c *customizations) process(d *schema.FieldData) error {
    15  	cmd, err := c.Opts.Bindata.RenderString(d.Get("run_command").(string))
    16  	if err != nil {
    17  		return fmt.Errorf("Error processing 'run_command': %s", err)
    18  	}
    19  
    20  	c.Opts.Bindata.Context["dep_run_command"] = cmd
    21  
    22  	c.Opts.Bindata.Context["dev_go_version"] = d.Get("go_version")
    23  
    24  	// Go is really finicky about the GOPATH. To help make the dev
    25  	// environment and build environment more correct, we attempt to
    26  	// detect the GOPATH automatically.
    27  	//
    28  	// We use this GOPATH for example in Vagrant to setup the synced
    29  	// folder directly into the GOPATH properly. Magic!
    30  	gopathPath := d.Get("go_import_path").(string)
    31  	if gopathPath == "" {
    32  		var err error
    33  		c.Opts.Ctx.Ui.Header("Detecting application import path for GOPATH...")
    34  		gopathPath, err = DetectImportPath(c.Opts.Ctx)
    35  		if err != nil {
    36  			return err
    37  		}
    38  	}
    39  
    40  	folderPath := "/vagrant"
    41  	if gopathPath != "" {
    42  		folderPath = "/opt/gopath/src/" + gopathPath
    43  	}
    44  
    45  	c.Opts.Bindata.Context["import_path"] = gopathPath
    46  	c.Opts.Bindata.Context["shared_folder_path"] = folderPath
    47  
    48  	return nil
    49  }