There are times, mostly for logging and debugging, when you have a slice of a given type that you would like to print to a log file or just convert to a CSV of values.
A quick and easy way to convert a slice to a CSV in Golang is to use the json module to Marshal it a JSON encoded array.
package main
import (
"encoding/json"
"fmt"
)
func main() {
ints := []int64{1, 2, 3, → Continue reading “Convert a Slice of Any Type to a CSV in Go”