当前位置: 首页>>代码示例>>Golang>>正文


Golang Writer.WriteAll方法代码示例

本文整理汇总了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)
}
开发者ID:kjk,项目名称:contentstore,代码行数:11,代码来源:store.go

示例2: writeAllAtOnce

func writeAllAtOnce(writer *csv.Writer, data [][]string) {
	writer.WriteAll(data)
	writer.Flush()
}
开发者ID:robertojrojas,项目名称:go-database-frameworks-and-tools,代码行数:4,代码来源:main.go

示例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)
}
开发者ID:jchannon,项目名称:negotiator,代码行数:82,代码来源:csvprocessor.go


注:本文中的encoding/csv.Writer.WriteAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。