本文整理匯總了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)
}