shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
992 stars 84 forks source link

Feature: Add support to use standalone library / package #247

Closed mirusky closed 9 months ago

mirusky commented 11 months ago

Prerequisites

Describe your issue

Currently I have a small project that consumes CSV data and instead of rewriting or copy/paste the code, I'd like to know if it's possible to make the functions work standalone / importable stuff.

Something like the pgconfig has made. They have a project structure like that:

.
├── cmd
│   ├── api # cobra command
│   └── pgconfigctl # cobra command
├── pkg # commands functionalities that can be imported (used by cmd folder)
│   ├── category 
│   ├── defaults
│   ├── docs
│   ├── errors
│   ├── format
│   ├── input
│   ├── rules
│   └── version
├── go.mod
└── go.sum

Then we can use the pkg from other projects like:

package main

import (
    "fmt"

    "github.com/pgconfig/api/pkg/version"
)

func main() {
    fmt.Printf("pgconfigctl - %s\n", version.Pretty())
}

So users can do somethink like, on their own code:

// github.com/mirusky/project-x
package main

import (
    "github.com/shenwei356/csvtk/pkg/csv2json"
)

func main() {
    options := []csv2json.Option{}
    jsonBytes, err := csv2json.Run("my-file", options...)
}
shenwei356 commented 11 months ago

Sadly, it's not supported. You can try https://github.com/johnkerl/miller, which is also in Go.