mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-10 15:52:27 +08:00
doc: add doc for WriteMapsToCsv
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user