Created
May 19, 2019 17:29
-
-
Save anirudh-chhangani/83f215045f24f8f47780b43268389673 to your computer and use it in GitHub Desktop.
tabular struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"github.com/fatih/structs" | |
"github.com/olekukonko/tablewriter" | |
) | |
type printable struct { | |
A int | |
B string | |
} | |
func (p printable) GoString() string { | |
_ = structs.Values(p) | |
fields := structs.Fields(p) | |
var buf []byte | |
_table := tablewriter.NewWriter(bytes.NewBuffer(buf)) | |
_table.SetHeader(fields) | |
return "" | |
} | |
func main(){ | |
a := printable{123, "lala"} | |
fmt.Printf("%#v", a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment