本文整理汇总了Golang中encoding/csv.Writer.WriteAll方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.WriteAll方法的具体用法?Golang Writer.WriteAll怎么用?Golang Writer.WriteAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类encoding/csv.Writer
的用法示例。
在下文中一共展示了Writer.WriteAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeBlobRec
func writeBlobRec(csvWriter *csv.Writer, blob *blob) error {
sha1Str := hex.EncodeToString(blob.sha1[:])
rec := [][]string{
{
sha1Str,
strconv.Itoa(blob.nSegment),
strconv.Itoa(blob.offset),
strconv.Itoa(blob.size),
}}
return csvWriter.WriteAll(rec)
}
示例2: writeAllAtOnce
func writeAllAtOnce(writer *csv.Writer, data [][]string) {
writer.WriteAll(data)
writer.Flush()
}
示例3: process
func (p *csvProcessor) process(writer *csv.Writer, dataModel interface{}) error {
debug("csvProcessor.process %T\n", dataModel)
switch v := dataModel.(type) {
case string:
return writer.Write([]string{v})
case []string:
return writer.Write(v)
case [][]string:
return writer.WriteAll(v)
}
value := reflect.Indirect(reflect.ValueOf(dataModel))
debug(" is %v\n", value.Kind())
switch value.Kind() {
case reflect.Struct:
if value.NumField() == 0 {
return nil // nothing to write
}
return writeStructFields(writer, value, dataModel)
case reflect.Array, reflect.Slice:
if value.Len() == 0 {
return nil // nothing to write
}
v0 := reflect.Indirect(value.Index(0))
k0 := v0.Kind()
if reflect.Bool <= k0 && k0 <= reflect.Complex128 {
debug(" -- containing scalars\n")
return writeArrayOfScalars(writer, value)
}
switch k0 {
case reflect.Struct:
if v0.NumField() == 0 {
return nil // nothing to write
}
debug(" -- v0 is Struct\n")
_, ok := v0.Interface().(fmt.Stringer)
if ok {
return writeArrayOfStringers(writer, value)
}
return writeArrayOfStructFields(writer, value, dataModel)
case reflect.Array, reflect.Slice:
if v0.Len() == 0 {
return nil // nothing to write
}
debug(" -- v0 is Array/Slice\n")
v00 := reflect.Indirect(v0.Index(0))
k00 := v00.Kind()
debug(" -- v00 is %v\n", k00)
if reflect.Bool <= k00 && k00 <= reflect.Complex128 {
return write2DArrayOfScalars(writer, value)
} else if k00 == reflect.Struct {
_, ok := v00.Interface().(fmt.Stringer)
if ok {
return write2DArrayOfStringers(writer, value)
}
}
default:
debug(" -- v0 is %v -- ignored\n", k0)
}
}
s, ok := dataModel.(fmt.Stringer)
if ok {
return writer.Write([]string{s.String()})
}
return fmt.Errorf("Unsupported type for CSV: %T", dataModel)
}