github.com/drone/runner-go@v1.12.0/environ/provider/util.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package provider
     6  
     7  // ToMap is a helper function that converts a list of
     8  // variables to a map.
     9  func ToMap(src []*Variable) map[string]string {
    10  	dst := map[string]string{}
    11  	for _, v := range src {
    12  		dst[v.Name] = v.Data
    13  	}
    14  	return dst
    15  }
    16  
    17  // ToSlice is a helper function that converts a map of
    18  // environment variables to a slice.
    19  func ToSlice(src map[string]string) []*Variable {
    20  	var dst []*Variable
    21  	for k, v := range src {
    22  		dst = append(dst, &Variable{
    23  			Name: k,
    24  			Data: v,
    25  		})
    26  	}
    27  	return dst
    28  }
    29  
    30  // FilterMasked is a helper function that filters a list of
    31  // variable to return a list of masked variables only.
    32  func FilterMasked(v []*Variable) []*Variable {
    33  	var filtered []*Variable
    34  	for _, vv := range v {
    35  		if vv.Mask {
    36  			filtered = append(filtered, vv)
    37  		}
    38  	}
    39  	return filtered
    40  }
    41  
    42  // FilterUnmasked is a helper function that filters a list of
    43  // variable to return a list of masked variables only.
    44  func FilterUnmasked(v []*Variable) []*Variable {
    45  	var filtered []*Variable
    46  	for _, vv := range v {
    47  		if vv.Mask == false {
    48  			filtered = append(filtered, vv)
    49  		}
    50  	}
    51  	return filtered
    52  }