encode

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 16 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 encode writes a table of typed rows in a file format: the last stage of the export pipeline (dataset, selection, format).

Every format escapes for itself, because each is read by something different: a spreadsheet runs a cell starting with "=", a browser runs a "</table><script>", PHP ends a string at an unescaped quote, a Markdown table splits on "|". Each format has a test for its own hazard.

Index

Constants

View Source
const ClientCSV = "hosts-csv"

ClientCSV is the generic client CSV's name in the pipeline, where "csv" is the table CSV.

Variables

View Source
var Clients = map[string]Client{
	"csv":              {Name: "csv", Client: "any client that imports a CSV (Royal TS, Xshell, SecureCRT's import script, a spreadsheet)", Render: renderGenericCSV},
	"windows-terminal": {Name: "windows-terminal", Client: "Windows Terminal (a JSON fragment)", ViaSSH: true, Render: renderWindowsTerminal},
	"iterm2":           {Name: "iterm2", Client: "iTerm2 (Dynamic Profiles)", ViaSSH: true, Render: renderITerm2},
	"putty":            {Name: "putty", Client: "PuTTY and KiTTY (a .reg file)", Render: renderPuTTY},
	"remmina":          {Name: "remmina", Client: "Remmina (one .remmina file per host)", Render: renderRemmina},
	"securecrt": {Name: "securecrt",
		Client: "SecureCRT (an XML settings file for File > Import Settings; Termius imports it too)", Render: renderSecureCRT},
	"mobaxterm": {Name: "mobaxterm",
		Client: "MobaXterm (a .mxtsessions file for Sessions > Import; Termius imports it too)", Render: renderMobaXterm},
}

Clients are the SSH client formats, by their own name ("csv" is hosts-csv in the pipeline).

View Source
var ErrNotHosts = errors.New("encode: a host format writes host rows, not a table")

ErrNotHosts is a host format asked to write a table.

View Source
var ErrUnknownFormat = errors.New("encode: unknown format")

ErrUnknownFormat is a format this package does not have.

View Source
var GenericCSVColumns = []string{"alias", "group", "hostname", "port", "user", "key_path", "tags"}

GenericCSVColumns are the generic export's columns.

View Source
var TermiusColumns = []string{"Groups", "Label", "Tags", "Hostname/IP", "Protocol", "Port", "Username", "Password"}

TermiusColumns is the header of Termius's CSV import template, as the third-party exporters written against it reproduce it (Termius 9.x). Termius publishes the template only as a download inside the app, so this is the one place to change if it moves.

Functions

func Bundle

func Bundle(f Format, exp *ClientExport) ([]byte, error)

Bundle is an export as one file: its only file as it is, or, for a format that writes a file per host (its extension is zip), every file in a zip under its own name.

func ClientNames

func ClientNames() []string

ClientNames are the client format names, sorted.

func FileName

func FileName(f Format, exp *ClientExport, base string) string

FileName is what a host format's file is called: the client's own name for it (authama-putty.reg), or the zip's.

func HostNames

func HostNames() []string

HostNames lists the host formats, sorted.

func Names

func Names() []string

Names lists the formats, sorted.

func TableNames

func TableNames() []string

TableNames lists the table formats, sorted.

func TermiusCSV

func TermiusCSV(hosts []Host) (string, error)

TermiusCSV is a Termius CSV import of hosts, one row each: group = profile, label = alias, tags = the host's tags. No password is ever written: the column is part of the template and stays empty.

func Text

func Text(v any) string

Text is a value as text: lists joined by spaces, as the CSVs always wrote them.

Types

type Client

type Client struct {
	Name, Client string
	// ViaSSH formats launch `ssh <alias>`, so OpenSSH reads the managed config
	// and a ProxyCommand or VM host works as it does at the terminal; the
	// others hand the client a host, port, user and key and keep only hosts
	// the client can reach on its own.
	ViaSSH bool
	Render func(hosts []Host) (*ClientExport, error)
}

Client is one SSH client's import format.

type ClientExport

type ClientExport struct {
	Files   []ClientFile
	Skipped []string
	Notes   []string
}

ClientExport is a rendered export: the files, the hosts left out with the reason for each, and notes the user needs to finish the import.

type ClientFile

type ClientFile struct {
	Name string
	Data []byte
}

ClientFile is one file an export writes: its name and its bytes.

type Format

type Format struct {
	Name      string // csv, json, ...
	Extension string // without the dot
	MediaType string
	Label     string // for a page: "CSV", "PHP array", ...
	Write     func(w io.Writer, t Table, o Options) error
	// Hosts is set on a host format (hosts.go): it writes the hosts a
	// selection kept, read from a HostSource, and Write refuses a table.
	Hosts func(src HostSource, aliases []string, o Options) (*ClientExport, error)
	// Client is the client format's own name in Clients, which the pipeline
	// may call otherwise: the generic "csv" client is "hosts-csv" there, since
	// "csv" is the table format.
	Client string
}

Format is one file format.

func Get

func Get(name string) (Format, error)

Get is the format of that name.

func (Format) IsHosts

func (f Format) IsHosts() bool

IsHosts reports a host format.

type Host

type Host struct {
	Group, Alias, Hostname, User string
	Port                         int
	Tags                         []string
	KeyFile                      string // absolute; "" when the key is in 1Password
	Agent                        string // the 1Password agent socket, when it is
}

Host is one host as an SSH client's import sees it: the profile as its group, the alias as its name, and the key as an absolute path.

type HostSource

type HostSource interface {
	// ClientHosts are the hosts named, as a client sees them. A host the
	// client cannot reach on its own (behind a ProxyCommand, when viaSSH is
	// false) or a git host (unless includeGit) is left out, with the reason
	// in skipped. client names the client in that reason.
	ClientHosts(aliases []string, client string, viaSSH, includeGit bool) (hosts []Host, skipped []string, err error)
	// SSHConfig is the managed config of exactly the hosts named, as
	// `authama ssh config export --flat` writes it for every host.
	SSHConfig(aliases []string) (string, error)
}

HostSource is what a host format reads.

type Options

type Options struct {
	NoHeader bool   // csv, tsv, markdown, html: leave the heading row out
	Compact  bool   // json, js, php, yaml: no indentation
	Shape    string // json, js, php, yaml: "objects" (default) or "table" ({columns, rows})
	Title    string // html: the page title
	// IncludeGit keeps git hosts (user git, or a github or gitlab provider)
	// in a host format, which otherwise leaves them out: they are not shells.
	IncludeGit bool
}

Options tune a format. A format ignores what does not apply to it.

type Table

type Table struct {
	Columns []string
	Rows    [][]any
}

Table is what a format writes: column headings, and rows of strings, ints, int64s, bools and lists of strings, in column order.

Jump to

Keyboard shortcuts

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