doc: add doc for WriteMapsToCsv

This commit is contained in:
dudaodong committed 2024-01-01 17:40:32 +08:00
1 parent 3482f80d1c
commit 4afc838937
9 files changed
+159 -10

No files matched your search

+22
View File
@@ -3,6 +3,7 @@ package fileutil
import (
"fmt"
"io"
"log"
"os"
)
@@ -331,6 +332,27 @@ func ExampleWriteCsvFile() {
// [[Lili 22 female] [Jim 21 male]]
}
func ExampleWriteMapsToCsv() {
csvFilePath := "./testdata/test3.csv"
records := []map[string]string{
{"Name": "Lili", "Age": "22", "gender": "female"},
{"Name": "Jim", "Age": "21", "gender": "male"},
}
err := WriteMapsToCsv(csvFilePath, records, false, ';')
if err != nil {
log.Fatal(err)
}
content, err := ReadCsvFile(csvFilePath, ';')
fmt.Println(content)
// Output:
// [[Name Age gender] [Lili 22 female] [Jim 21 male]]
}
func ExampleWriteStringToFile() {
filepath := "./test.txt"