dataview

package
v2.57.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NamespaceSeparator = "::"

Functions

This section is empty.

Types

type ColumnSpec added in v2.57.0

type ColumnSpec struct {
	// Name is an optional column alias
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Path is the selector of the property (or properties) to display
	Path string `json:"path" yaml:"path"`

	// Width is a fixed column width in characters
	Width int `json:"width,omitempty" yaml:"width,omitempty"`

	// MinWidth is the minimum column width in characters
	MinWidth int `json:"minWidth,omitempty" yaml:"minWidth,omitempty"`

	// MaxWidth is the maximum column width in characters
	MaxWidth int `json:"maxWidth,omitempty" yaml:"maxWidth,omitempty"`
}

ColumnSpec is a single entry of a view's columns. It is either a selector string (the same syntax as the --select flag, e.g. "id", "tags.**" or the alias form "model:c8y_Hardware.model"), or an object which can also constrain the column width in table output:

{"name": "model", "path": "c8y_Hardware.model", "width": 20}

func NewColumnSpecs added in v2.57.0

func NewColumnSpecs(selectors ...string) []ColumnSpec

NewColumnSpecs creates column specs from selector strings

func (ColumnSpec) HasWidth added in v2.57.0

func (c ColumnSpec) HasWidth() bool

HasWidth checks if the column constrains the column width

func (ColumnSpec) MarshalJSON added in v2.57.0

func (c ColumnSpec) MarshalJSON() ([]byte, error)

MarshalJSON writes the column as a string if it does not use any object properties

func (ColumnSpec) MarshalYAML added in v2.57.0

func (c ColumnSpec) MarshalYAML() (any, error)

MarshalYAML writes the column as a string if it does not use any object properties

func (ColumnSpec) Matches added in v2.57.0

func (c ColumnSpec) Matches(column string) bool

Matches checks if a rendered table column was produced by the column spec. The column name is either the alias, the property path, or (for wildcard paths) any property path matching the wildcard, including the root of a wildcard, e.g. "tags" for "tags.**" (scalar arrays are displayed under the root)

func (ColumnSpec) Selector added in v2.57.0

func (c ColumnSpec) Selector() string

Selector returns the selector string used to select the column's properties

func (ColumnSpec) String added in v2.57.0

func (c ColumnSpec) String() string

String returns the selector string

func (*ColumnSpec) UnmarshalJSON added in v2.57.0

func (c *ColumnSpec) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts either a selector string or a column object

func (*ColumnSpec) UnmarshalYAML added in v2.57.0

func (c *ColumnSpec) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts either a selector string or a column object

func (ColumnSpec) Validate added in v2.57.0

func (c ColumnSpec) Validate() error

Validate checks the column for invalid values

type Columns added in v2.57.0

type Columns []ColumnSpec

Columns is a list of view columns

func (Columns) HasWidthRules added in v2.57.0

func (c Columns) HasWidthRules() bool

HasWidthRules checks if any column constrains its width

func (Columns) Selectors added in v2.57.0

func (c Columns) Selectors() []string

Selectors returns the selector strings of the columns

func (Columns) WidthRule added in v2.57.0

func (c Columns) WidthRule(column string) (ColumnSpec, bool)

WidthRule returns the first column with width constraints which matches the rendered column name

type DataView

type DataView struct {
	Paths       []string
	Extension   string
	Pattern     string
	Definitions []Definition
	Logger      *logger.Logger
	ActiveView  *Definition
	// contains filtered or unexported fields
}

DataView data view containing predefined views

func NewDataView

func NewDataView(pattern string, extension string, log *logger.Logger, paths ...string) (*DataView, error)

NewDataView creates a new data view which selected a view based in json data

func (*DataView) ClearActiveView

func (v *DataView) ClearActiveView()

ClearActiveView clear the active view

func (*DataView) GetActiveView

func (v *DataView) GetActiveView() *Definition

GetActiveView get the active view

func (*DataView) GetDefinitionByName added in v2.57.0

func (v *DataView) GetDefinitionByName(pattern string) (*Definition, error)

GetDefinitionByName get the first view definition which matches the name. Accepts wildcard name

func (*DataView) GetDefinitions

func (v *DataView) GetDefinitions() []Definition

func (*DataView) GetView

func (v *DataView) GetView(r *ViewData) ([]string, error)

func (*DataView) GetViewByName

func (v *DataView) GetViewByName(pattern string) ([]string, error)

GetViewByName get view by name. Accepts wildcard name

func (*DataView) GetViews

func (v *DataView) GetViews(pattern string) ([]Definition, error)

GetViews get a list of view names

func (*DataView) LoadDefinitions

func (v *DataView) LoadDefinitions() error

LoadDefinitions load the view definitions

func (*DataView) SetActiveView added in v2.57.0

func (v *DataView) SetActiveView(definition *Definition)

SetActiveView sets the active view, so it is used regardless of the response contents

type Definition

type Definition struct {
	FileName      string   `json:"-"`
	Path          string   `json:"-"`
	Extension     string   `json:"-"`
	Name          string   `json:"name,omitempty"`
	Priority      int      `json:"priority,omitempty"`
	Fragments     []string `json:"fragments,omitempty"`
	Type          string   `json:"type,omitempty"`
	RequestPath   string   `json:"requestPath,omitempty"`
	RequestMethod string   `json:"requestMethod,omitempty"`
	ContentType   string   `json:"contentType,omitempty"`
	Self          string   `json:"self,omitempty"`
	Columns       Columns  `json:"columns,omitempty"`

	// AutoMatch controls if the view is considered when automatically detecting a view.
	// Set it to false for views which should only be used by name, e.g. via --view <name>,
	// or from the view of an extension API command. Defaults to true
	AutoMatch *bool `json:"autoMatch,omitempty"`
}

Definition contains the view definition of when to use a specific view

func (*Definition) FQDN added in v2.30.0

func (d *Definition) FQDN() string

func (*Definition) IsAutoMatch added in v2.57.0

func (d *Definition) IsAutoMatch() bool

IsAutoMatch checks if the view is considered when automatically detecting a view

type DefinitionCollection

type DefinitionCollection struct {
	Definitions []Definition `json:"definitions,omitempty"`
}

DefinitionCollection collection of view definitions

type ViewData added in v2.30.0

type ViewData struct {
	ResponseBody *gjson.Result
	ContentType  string
	Response     *http.Response
	Request      *http.Request
}

Jump to

Keyboard shortcuts

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