github.com/blend/go-sdk@v1.20240719.1/stringutil/csv.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  import (
    11  	"encoding/csv"
    12  	"strings"
    13  )
    14  
    15  // CSV produces a csv from a given set of values.
    16  // Deprecated: Use `encoding/csv.Writer` directly instead.
    17  func CSV(values []string) string {
    18  	var builder strings.Builder
    19  	writer := csv.NewWriter(&builder)
    20  	if err := writer.Write(values); err != nil {
    21  		return ""
    22  	}
    23  	writer.Flush()
    24  	if err := writer.Error(); err != nil {
    25  		return ""
    26  	}
    27  	return strings.TrimSpace(builder.String())
    28  }