dataview

package
v0.0.0-...-5746e46 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dataview provides a way to view Go values as tabular HTML if the values can be represented as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func From

func From(data any, options ...Option) html.Content

From converts a Go value into HTML, converting it into JSON first and parsing it with GJSON.

func FromGJSON

func FromGJSON(data gjson.Result, options ...Option) html.Content

FromGJSON converts a GJSON result into HTML. This is the most efficient way to use dataview if you already have a GJSON result.

func FromJSON

func FromJSON(js []byte, options ...Option) html.Content

FromJSON converts a JSON document into HTML, parsing it with GJSON -- the provided JSON MUST be valid.

func Stylesheet

func Stylesheet(options ...Option) string

Stylesheet will return the structural CSS needed to render the dataview. The options are currently ignored, but are present in case we need to add options like a class prefix in the future.

Types

type Option

type Option func(*config)

func Hook

func Hook(rx *regexp.Regexp, hookFn func(path string, data gjson.Result) html.Content) Option

Hook registers a function that replaces how a value is rendered if the path to the value matches the provided pattern.

Patterns are regex patterns that match paths like .persons.0.name or .persons.0.address.city. If a hook returns nil, the default rendering is used.

func TableHook

func TableHook(rx *regexp.Regexp, hookFn func(path string, data gjson.Result) gjson.Result) Option

TableHook registers a function that converts an array containing at least one object into some other GJSON result if the path to the array matches the provided pattern. TableHooks are applied before Hooks and use the same path syntax.

Jump to

Keyboard shortcuts

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