github.com/Hashicorp/packer@v1.3.2/common/http_config.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/hashicorp/packer/template/interpolate"
     7  )
     8  
     9  // HTTPConfig contains configuration for the local HTTP Server
    10  type HTTPConfig struct {
    11  	HTTPDir     string `mapstructure:"http_directory"`
    12  	HTTPPortMin uint   `mapstructure:"http_port_min"`
    13  	HTTPPortMax uint   `mapstructure:"http_port_max"`
    14  }
    15  
    16  func (c *HTTPConfig) Prepare(ctx *interpolate.Context) []error {
    17  	// Validation
    18  	var errs []error
    19  
    20  	if c.HTTPPortMin == 0 {
    21  		c.HTTPPortMin = 8000
    22  	}
    23  
    24  	if c.HTTPPortMax == 0 {
    25  		c.HTTPPortMax = 9000
    26  	}
    27  
    28  	if c.HTTPPortMin > c.HTTPPortMax {
    29  		errs = append(errs,
    30  			errors.New("http_port_min must be less than http_port_max"))
    31  	}
    32  
    33  	return errs
    34  }