UTF16LEのBOM付きでエンコード、タブ区切りで出力。
main.go
package main
import (
"fmt"
"encoding/csv"
"bytes"
"io/ioutil"
"golang.org/x/text/transform"
"golang.org/x/text/encoding/unicode"
"os"
)
func main() {
buf := new(bytes.Buffer)
w := csv.NewWriter(buf)
w.Comma = '\t'
w.Write([]string{"name", "type"})
w.Write([]string{"blacksmith🔨", "villager"})
w.Write([]string{"creeper💣", "enemy"})
w.Write([]string{"zonbie😡", "enemy"})
w.Flush()
utf16byte, err := ioutil.ReadAll(transform.NewReader(
buf,
unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewEncoder()))
if err != nil {
fmt.Println(err)
}
file, err := os.OpenFile("utf16le.csv", os.O_WRONLY|os.O_CREATE, 0600)
file.Write(utf16byte)
}