https://github.com/qnester/tablex
https://github.com/qnester/tablex
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/qnester/tablex
- Owner: QNester
- Created: 2023-03-01T11:07:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-03T13:06:56.000Z (over 3 years ago)
- Last Synced: 2025-03-15T03:28:19.755Z (about 1 year ago)
- Language: Go
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Tablex
[](https://github.com/QNester/tablex/actions/workflows/tests.yml)
Render your structs with [go-pretty/table](https://github.com/jedib0t/go-pretty/tree/main/table) in go-way tags.
## Installation
`go get https://github.com/QNester/tablex`
## Usage
1. Set up your table (see more in [go-pretty/table doc](https://github.com/jedib0t/go-pretty/tree/main/table))
2. Add `tablex` as a tag to your struct type
3. Render the table via Renderer interface.
```go
import (
"github.com/QNester/tablex"
"github.com/jedib0t/go-pretty/v6/table"
)
type myData struct {
ID int `tablex:"header:#"`
Name string `table:"Name"`
}
func main() {
writer := table.NewWriter()
renderer := tablex.NewRenderer(writer)
table := renderer.Render()
print(table)
}
```
Result of the running this program:
```text
+---+------------+
| # | NAME |
+---+------------+
| 1 | Joh Watson |
+---+------------+
```
See more [examples](./internal/examples) for usage information.
### Additional information
1. Use `tablex.RenderOptions` to set default empty value and table format (Text Table/CSV/HTML/MD)
```go
renderer := tablex.NewRenderer(
writer,
tablex.RendererOptions{
EmptyValue: "no data", // what you want to see if some of your fields' data equals nil
Format: tablex.RenderFormatHTML, // rendering format
},
)
```
2. You can use `RendererMock` in your tests.