native

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 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

Overview

Package native shells out to a format's own CLI to produce a golden reference render (SVG) to validate the WebGL/SVG paths against. Running an external process is gated three ways. A tool must be registered for the file's extension, the operator must allowlist it (--enable-native <tool>), and its binary must be on PATH. Tools run under exec (no shell), on an already mount-safe absolute path, into a temp output dir, under a timeout. See docsite/content/build/native-verification.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTool     = errors.New("no native renderer for this format")
	ErrNotEnabled = errors.New("native renderer not enabled")
	ErrNotFound   = errors.New("native renderer binary not found on PATH")
)

Sentinel errors, mapped to Connect codes by the caller.

Functions

func Available

func Available(absPath string, enabled map[string]bool) bool

Available reports whether NATIVE can be served for absPath, meaning a renderer is registered (by extension, or by sniffing a .sch), its tool is enabled, and its binary is installed.

func OpenArgs

func OpenArgs(absPath string) (bin string, args []string, err error)

OpenArgs returns the command (binary + args) that opens absPath in its native GUI tool on the current platform, or ErrNoTool when no native GUI is known for the format or platform. It launches nothing, so the caller execs the result and the command stays unit testable. On macOS KiCad opens via `open -a`. Otherwise, and for the X11 schematic editors, the binary runs directly, so a missing binary surfaces at exec time.

func RenderFile

func RenderFile(ctx context.Context, absPath string, page int) (string, error)

RenderFile renders one page (1-based) of absPath to SVG using its registered native tool, for direct CLI use, uncached. Unlike Cache.Render it does NOT consult the operator allowlist, which guards a shared server against shelling out on a request, whereas invoking the CLI is itself the operator's consent. It returns ErrNoTool or ErrNotFound for the other two gates.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache memoizes rendered SVGs by (path, mtime, page) so navigating sheets does not re-shell for an unchanged file.

func NewCache

func NewCache() *Cache

NewCache returns an empty render cache; one per server.

func (*Cache) Render

func (c *Cache) Render(ctx context.Context, absPath string, page int, enabled map[string]bool) (string, error)

Render renders one page of absPath to SVG using its registered, enabled tool. page is 1-based. It returns ErrNoTool / ErrNotEnabled / ErrNotFound for the gate failures so the caller can map them to Connect codes.

Jump to

Keyboard shortcuts

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