github.com/secure-build/gitlab-runner@v12.5.0+incompatible/executors/docker/internal/volumes/parser/volume.go (about)

     1  package parser
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  type Volume struct {
     8  	Source          string
     9  	Destination     string
    10  	Mode            string
    11  	BindPropagation string
    12  }
    13  
    14  func newVolume(source string, destination string, mode string, bindPropagation string) *Volume {
    15  	return &Volume{
    16  		Source:          source,
    17  		Destination:     destination,
    18  		Mode:            mode,
    19  		BindPropagation: bindPropagation,
    20  	}
    21  }
    22  
    23  func (v *Volume) Definition() string {
    24  	parts := make([]string, 0)
    25  	builder := strings.Builder{}
    26  
    27  	if v.Source != "" {
    28  		parts = append(parts, v.Source)
    29  	}
    30  
    31  	parts = append(parts, v.Destination)
    32  
    33  	if v.Mode != "" {
    34  		parts = append(parts, v.Mode)
    35  	}
    36  
    37  	builder.WriteString(strings.Join(parts, ":"))
    38  
    39  	if v.BindPropagation != "" {
    40  		separator := ":"
    41  		if v.Mode != "" {
    42  			separator = ","
    43  		}
    44  
    45  		builder.WriteString(separator)
    46  		builder.WriteString(v.BindPropagation)
    47  	}
    48  
    49  	return builder.String()
    50  }
    51  
    52  func (v *Volume) Len() int {
    53  	len := 0
    54  
    55  	if v.Source != "" {
    56  		len++
    57  	}
    58  
    59  	if v.Destination != "" {
    60  		len++
    61  	}
    62  
    63  	return len
    64  }