csvton

package module
v0.0.0-...-fbc974a Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: MIT Imports: 4 Imported by: 0

README

go-csv-output-option

A simple Go library that optionally controls items to be output to CSV.

Usage

package main

import (
	"log"

	csvton "github.com/haton14/go-csv-output-option"
)

type ExampleOption struct {
	HasName    bool `csv:"has_name"`
	HasAddress bool `csv:"has_address"`
}

type ExampleData struct {
	ID      int
	Name    string `csv:"has_name"`
	Address string `csv:"has_address"`
}

func main() {
	data := ExampleData{
		ID:      111,
		Name:    "taro",
		Address: "tokyo",
	}

	opt, err := csvton.ParseOption(
		ExampleOption{
			HasName:    true,
			HasAddress: false,
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	opt.Output("examlpe.csv", data)
}
$ cat examlpe.csv
111,taro

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	// contains filtered or unexported fields
}

func ParseOption

func ParseOption(opt any) (*Option, error)

func (Option) Output

func (opt Option) Output(fileName string, data any) error

Jump to

Keyboard shortcuts

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