gitlab.com/evatix-go/core@v1.3.55/coreappend/PrependAppendAnyItemsToStringsSkipOnNil.go (about)

     1  package coreappend
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  )
     8  
     9  func PrependAppendAnyItemsToStringsSkipOnNil(
    10  	prependItem, appendItem interface{},
    11  	anyItems ...interface{},
    12  ) []string {
    13  	slice := make([]string, 0, len(anyItems)+3)
    14  
    15  	if prependItem != nil {
    16  		slice = append(
    17  			slice,
    18  			fmt.Sprintf(constants.SprintValueFormat, prependItem))
    19  	}
    20  
    21  	for _, item := range anyItems {
    22  		if item == nil {
    23  			continue
    24  		}
    25  
    26  		slice = append(
    27  			slice,
    28  			fmt.Sprintf(constants.SprintValueFormat, item))
    29  	}
    30  
    31  	if appendItem != nil {
    32  		slice = append(
    33  			slice,
    34  			fmt.Sprintf(constants.SprintValueFormat, appendItem))
    35  	}
    36  
    37  	return slice
    38  }