lenses

package
v0.0.0-...-4359601 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package lenses provides interfaces and methods necessary for implementing custom artifact viewers

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrGzipOffsetRead will be thrown when an offset read is attempted on a gzip-compressed object
	ErrGzipOffsetRead = errors.New("offset read on gzipped files unsupported")
	// ErrInvalidLensName will be thrown when a viewer method is called on a view name that has not
	// been registered. Ensure your viewer is registered using RegisterViewer and that you are
	// providing the correct viewer name.
	ErrInvalidLensName = errors.New("invalid lens name")
	// ErrFileTooLarge will be thrown when a size-limited operation (ex. ReadAll) is called on an
	// artifact whose size exceeds the configured limit.
	ErrFileTooLarge = errors.New("file size over specified limit")
	// ErrRequestSizeTooLarge will be thrown when any operation is called whose size exceeds the configured limit.
	ErrRequestSizeTooLarge = errors.New("request size over specified limit")
	// ErrContextUnsupported is thrown when attempting to use a context with an artifact that
	// does not support context operations (cancel, withtimeout, etc.)
	ErrContextUnsupported = errors.New("artifact does not support context operations")
)

Functions

func LastNLines

func LastNLines(a api.Artifact, n int64) ([]string, error)

LastNLines reads the last n lines from an artifact.

func LastNLinesChunked

func LastNLinesChunked(a api.Artifact, n, chunkSize int64) ([]string, error)

LastNLinesChunked reads the last n lines from an artifact by reading chunks of size chunkSize from the end of the artifact. Best performance is achieved by: argmin 0<chunkSize<INTMAX, f(chunkSize) = chunkSize - n * avgLineLength

func RegisterLens

func RegisterLens(lens Lens) error

RegisterLens registers new viewers

func ResourceDirForLens

func ResourceDirForLens(baseDir, name string) string

ResourceDirForLens returns the path to a lens's public resource directory.

func UnregisterLens

func UnregisterLens(viewerName string)

UnregisterLens unregisters lenses

Types

type Lens

type Lens interface {
	// Config returns a LensConfig that describes the lens.
	Config() LensConfig
	// Header returns a a string that is injected into the rendered lens's <head>
	Header(artifacts []api.Artifact, resourceDir string, config json.RawMessage, spyglassConfig config.Spyglass) string
	// Body returns a string that is initially injected into the rendered lens's <body>.
	// The lens's front-end code may call back to Body again, passing in some data string of its choosing.
	Body(artifacts []api.Artifact, resourceDir string, data string, config json.RawMessage, spyglassConfig config.Spyglass) string
	// Callback receives a string sent by the lens's front-end code and returns another string to be returned
	// to that frontend code.
	Callback(artifacts []api.Artifact, resourceDir string, data string, config json.RawMessage, spyglassConfig config.Spyglass) string
}

Lens defines the interface that lenses are required to implement in order to be used by Spyglass.

func GetLens

func GetLens(name string) (Lens, error)

GetLens returns a Lens or a remoteLens by name, if it exists; otherwise it returns an error.

type LensConfig

type LensConfig struct {
	// Name is the name of the lens. It must match the package name.
	Name string
	// Title is a human-readable title for the lens.
	Title string
	// Priority is used to determine where to position the lens. Higher is better.
	Priority uint
	// HideTitle will hide the lens title after loading if set to true.
	HideTitle bool
}

Directories

Path Synopsis
Package buildlog provides a build log viewer for Spyglass
Package buildlog provides a build log viewer for Spyglass
Package coverage provides a coverage viewer for Spyglass
Package coverage provides a coverage viewer for Spyglass
Package junit provides a junit viewer for Spyglass
Package junit provides a junit viewer for Spyglass
Package metadata provides a metadata viewer for Spyglass
Package metadata provides a metadata viewer for Spyglass
Package podinfo provides a coverage viewer for Spyglass
Package podinfo provides a coverage viewer for Spyglass

Jump to

Keyboard shortcuts

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