csv

package module
v0.0.0-...-70618a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 4 Imported by: 1

README

codecov

grpc gateway csv marshaler

This is an implementation of the runtime.Marshaler interface marshaling responses to csv.

You might register the marshaler using

mux := runtime.NewServeMux(runtime.WithMarshalerOption("text/csv", &csv.Marshaler{}))

Documentation on grpc-gateway custom marshalers may be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Marshaler

type Marshaler struct {
	runtime.Marshaler

	// RowDelim specifies the delimiter between rows
	RowDelim string
	// FieldDelim specifies the delimiter between fields
	FieldDelim string
	// InnerDelim specifies the delimiter of merged values (slices / maps) within one field.
	InnerDelim string

	// used to print types (e.g. int, float, ...)
	Printf func(format string, a ...any) string

	// NoHeader suppresses to render the header
	NoHeader bool
}

func (*Marshaler) ContentType

func (m *Marshaler) ContentType(v interface{}) string

ContentType returns 'text/csv'.

func (*Marshaler) Marshal

func (m *Marshaler) Marshal(i interface{}) ([]byte, error)

Marshal renders the structure in i as CSV.

If i is a slice or a struct that contains slices each slice is rendered to a CSV block. These top-level slices need to contain structs otherwise an error is returned. Each top-level slices is rendered to one block. The blocks are delimited by '---\n'. Empty slices or nil pointers are ignored.

Each csv block consists of a header (if NoHeader option is false) and multiple rows delimited by m.RowDelimi. Each row is a 'flat' representation of the corresponding slice elements:

  • struct fields are visible on top-level with own header delimited by m.FieldDelim
  • nested slices / maps are flatened delimited by m.InnerDelim

Directories

Path Synopsis
Package main is a reverse proxy.
Package main is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL