container

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionsBefore  = 0
	ActionsAfter   = 1
	ActionsExtract = 2
)

ActionsNav indices for ActionsPane.

View Source
const FailedStatus = "Request failed"

FailedStatus is the status line text for a request that failed; the error itself is shown in the response pane by ErrorView.

View Source
const (

	// KVColSecret marks a row whose value is encrypted at rest.
	KVColSecret = "sec"
)

Column IDs shared by the key/value tables.

Variables

View Source
var CertFileFilters = []ui.FileFilter{{Label: "Certificates", Exts: []string{".pem", ".crt", ".key"}}}

CertFileFilters limit a file dialog to certificate and key files.

Functions

func ActionsPane

func ActionsPane(th *theme.Theme, opts ActionsOpts) ui.View

ActionsPane renders a top horizontal nav with Before / After / Extract content.

func AddKVRow

func AddKVRow(t *ui.Table, onChange func())

func AddVariableRow

func AddVariableRow(t *ui.Table, defaultStatus int, markDirty func())

func AssistEditor

func AssistEditor(ed *ui.Editor, src vars.Source) *ui.Editor

AssistEditor gives a code editor the same variable completion and hover as the single-line fields. A body or a script may hold {{name}} placeholders wherever text is allowed, and a language server, when one is attached, keeps answering for everything else. It also lays the editor out with StyleCodeEditor.

func AssistField

func AssistField(n *ui.Node, src vars.Source) *ui.Node

AssistField gives a text field variable highlighting, completion, and a hover card explaining the placeholder under the pointer.

func AssistKV

func AssistKV(t *ui.Table, src vars.Source)

AssistKV gives a key/value table's value cells variable highlighting and completion. Keys are left alone: chapar substitutes values, not names.

func AssistURLField

func AssistURLField(n *ui.Node, src vars.Source) *ui.Node

AssistURLField is AssistField for an address bar, where {name} path parameters are marked up as well as {{name}} variables.

func AuthForm

func AuthForm(th *theme.Theme, id string, auth *domain.Auth, st *AuthState, catalog Catalog, markDirty func()) ui.View

AuthForm builds the auth type selector and sub-forms.

func BinaryFilePicker

func BinaryFilePicker(th *theme.Theme, id, path string, deps Deps, onChange func(string)) ui.View

BinaryFilePicker renders a file picker for binary request bodies.

func BodyHighlighter

func BodyHighlighter(kind string) highlight.Highlighter

BodyHighlighter returns a highlighter for the response body kind.

func CookieExpiry

func CookieExpiry(c domain.Cookie, now time.Time) string

CookieExpiry describes when a cookie expires relative to now.

func CookieFlags

func CookieFlags(c domain.Cookie) string

CookieFlags lists a cookie's attributes compactly, e.g. "Secure HttpOnly Lax".

func CookiesView

func CookiesView(id string, th *theme.Theme, ctx *ui.Ctx, deps Deps, s *CookiesState, raw bool) ui.View

CookiesView is the response Cookies tab. raw shows the headers as text.

func CopyCollection

func CopyCollection(c *domain.Collection) *domain.Collection

func CopyEnv

func CopyEnv(e *domain.Environment) *domain.Environment

func CopyRequest

func CopyRequest(r *domain.Request) *domain.Request

func DefaultResponseFilename

func DefaultResponseFilename(kind string) string

DefaultResponseFilename picks a filename from body kind.

func DisplayBody

func DisplayBody(res *egress.Response, raw bool) []byte

DisplayBody returns bytes for the response editor. When raw is true, the original body is shown; otherwise Pretty is preferred when available.

The result may be the response's own body buffer rather than a copy, so callers must treat it as read-only. Nothing mutates a response body once it is built, which is what lets the editor share it instead of copying tens of megabytes per tab — see ReplaceResponseEditor.

func DumpKV

func DumpKV(t *ui.Table) []domain.KeyValue

func DumpVariables

func DumpVariables(t *ui.Table) []domain.Variable

func EditorIndent

func EditorIndent() string

EditorIndent is one level of indentation as the editor settings ask for it.

func EnvEntries

func EnvEntries(values []domain.KeyValue) []vars.Entry

EnvEntries lists an environment's own enabled values, for the environment editor, where there is no active environment to read from.

func ErrorView

func ErrorView(id string, th *theme.Theme, ctx *ui.Ctx, deps Deps, msg string) ui.View

ErrorView shows a failed request: the confused Chapar with msg under it in red. Right-click copies the message.

func FlushAuth

func FlushAuth(auth *domain.Auth, st AuthState)

FlushAuth writes auth state into the domain auth object.

func FlushPostScript

func FlushPostScript(post *domain.PostRequest, ed *ui.Editor)

func FlushPreScript

func FlushPreScript(pre *domain.PreRequest, ed *ui.Editor)

func FormDataPane

func FormDataPane(th *theme.Theme, id string, fields *[]domain.FormField, deps Deps, markDirty func()) ui.View

FormDataPane renders multipart form fields.

func FormatBytes

func FormatBytes(n int) string

FormatBytes returns a human-readable size (e.g. "1.2 kB").

func FormatJSONBody

func FormatJSONBody(body, indent string) (string, error)

FormatJSONBody indents a JSON request body, keeping its {{variable}} placeholders.

A body may hold a placeholder where a value goes ({"id": {{id}}}), which is not JSON until the variable is substituted at send time. Each bare placeholder is swapped for a string sentinel before indenting and swapped back after, so it survives formatting exactly as written. A general-purpose formatter would drop it, silently losing part of the body.

indent is one level of indentation. A body that is not JSON, placeholders aside, is returned with the error and should be left as it is.

func FormatJSONEditor

func FormatJSONEditor(ed *ui.Editor, deps Deps)

FormatJSONEditor indents the JSON in ed as one edit the user can undo. A body that is not valid JSON is left alone and the reason is shown.

func FormatKeyValues

func FormatKeyValues(items []domain.KeyValue, title string) string

FormatKeyValues renders key-values as properties text.

func GRPCPostFromOptions

func GRPCPostFromOptions() []ui.SelectOption

func HTTPPostFromOptions

func HTTPPostFromOptions() []ui.SelectOption

func HeadersPane

func HeadersPane(th *theme.Theme, id string, headers *ui.Table, collectionID string, catalog Catalog, markDirty func()) ui.View

HeadersPane shows an editable headers table and optional inherited collection headers.

func HighlightOffNotice

func HighlightOffNotice(ed *ui.Editor) ui.View

HighlightOffNotice tells the reader why ed shows no syntax colors — its document is over the size limit — and offers to highlight it anyway.

func InfoPane

func InfoPane(th *theme.Theme, id string, req *domain.Request, descEd *ui.Editor, markDirty func()) ui.View

InfoPane builds the Info tab for request containers: optional name override and description.

func JSONBodyEditor

func JSONBodyEditor(id string, ed *ui.Editor, deps Deps, topRight *ui.Node) ui.View

JSONBodyEditor lays out ed, an editor holding a JSON body, with a Format button floating in its bottom-right corner, where it stays in reach however long the body is. topRight, when not nil, floats in the top-right corner, for an action such as loading an example body.

func LoadKV

func LoadKV(t *ui.Table, items []domain.KeyValue)

func LoadVariables

func LoadVariables(t *ui.Table, items []domain.Variable)

func MetadataPane

func MetadataPane(th *theme.Theme, id string, metadata *ui.Table, collectionID string, catalog Catalog, markDirty func()) ui.View

MetadataPane is HeadersPane for gRPC metadata, without a title: the tab holds nothing else. Collection headers are sent as metadata too, so they are listed as inherited.

func MutedParagraph added in v0.10.0

func MutedParagraph(s string) *ui.Node

MutedParagraph is body text in ForegroundMuted that wraps to its pane's width.

func NewBodyEditor

func NewBodyEditor(deps Deps, name, bodyType string, body []byte, opts ...ui.EditorOption) *ui.Editor

NewBodyEditor returns an editor for a request body of the given domain.RequestBodyType*.

func NewDescriptionEditor

func NewDescriptionEditor(description string) *ui.Editor

NewDescriptionEditor creates an editor for request metadata.description.

func NewKVTable

func NewKVTable(idPrefix string, onChange func()) *ui.Table

func NewResponseEditor added in v0.9.0

func NewResponseEditor(data []byte, hl highlight.Highlighter, opts ...ui.EditorOption) *ui.Editor

NewResponseEditor returns a read-only, soft-wrapped editor for something a server sent back: a body, headers, metadata or cookies. It can be searched, selected and copied, but not typed into. data is copied.

func NewScriptEditor

func NewScriptEditor(deps Deps, phase scripting.Phase, name, script string) *ui.Editor

NewScriptEditor returns an editor for a Python pre/post-request script. Scripts run against the active environment, so the editor completes and explains the same {{variable}} placeholders the request's fields do.

func NewSecretKVTable

func NewSecretKVTable(idPrefix string, onChange func(), s SecretsUI) *ui.Table

NewSecretKVTable is NewKVTable plus a lock column that marks a row secret and an eye that reveals a secret value.

func NewVariablesTable

func NewVariablesTable(id string, fromOptions []ui.SelectOption, markDirty func()) *ui.Table

NewVariablesTable creates a variables extraction table.

func ParamEntries

func ParamEntries(t *ui.Table) []vars.Entry

ParamEntries lists a table's keys as path-parameter entries.

func PickFolder

func PickFolder(deps Deps, title string, onPick func(string))

PickFolder opens a folder picker, for choosing an import root.

func PickProtoFiles

func PickProtoFiles(deps Deps, onPick func([]string))

PickProtoFiles opens a file dialog that takes one or more .proto files.

func PostRequestNotice

func PostRequestNotice(id string, ctx *ui.Ctx, deps Deps, res *egress.Response) ui.View

PostRequestNotice shows why the post-request actions failed, above a response that still arrived. It is nil when they did not fail. Right-click copies the message.

func PostRequestPane

func PostRequestPane(th *theme.Theme, deps Deps, post *domain.PostRequest, opts PrePostOpts, scriptEd **ui.Editor, preview string, markDirty func()) ui.View

PostRequestPane renders post-request configuration.

func PreRequestPane

func PreRequestPane(th *theme.Theme, deps Deps, pre *domain.PreRequest, opts PrePostOpts, scriptEd **ui.Editor, markDirty func()) ui.View

PreRequestPane renders pre-request configuration.

func PreviewPostSet

func PreviewPostSet(set domain.PostRequestSet, res *egress.Response) string

PreviewPostSet returns a preview value for a post-request set-env rule.

func RenameCollection

func RenameCollection(deps Deps, col *domain.Collection, name string)

RenameCollection persists a collection name immediately on EditableLabel commit.

func RenameEnvironment

func RenameEnvironment(deps Deps, env *domain.Environment, name string)

RenameEnvironment persists an environment name immediately on EditableLabel commit.

func RenameRequest

func RenameRequest(deps Deps, req *domain.Request, name string)

RenameRequest persists a request name immediately on EditableLabel commit.

func ReplaceEditor

func ReplaceEditor(old *ui.Editor, data []byte, hl highlight.Highlighter) *ui.Editor

ReplaceEditor closes the previous editor and returns a new read-only one with data. data is copied, so the caller may keep using it.

func ReplaceResponseEditor

func ReplaceResponseEditor(old *ui.Editor, res *egress.Response, raw bool) *ui.Editor

ReplaceResponseEditor rebuilds the response body editor for res.

The editor is built over the display bytes without copying them. Response bodies and their formatted forms are never modified after the response is built, so the editor can read them in place; for a large body that saves a full copy of the document per tab.

func RequestBreadcrumb

func RequestBreadcrumb(req *domain.Request) string

RequestBreadcrumb returns collection prefix text for a request.

func ResponseEditorMenu

func ResponseEditorMenu(ed *ui.Editor, ctx *ui.Ctx, deps Deps, defaultName string) ui.View

ResponseEditorMenu adds Save… to the editor's right-click menu and makes Copy take the whole body when nothing is selected.

func ResponseTabsRow

func ResponseTabsRow(id string, th *theme.Theme, tabs []ui.TabModel, selected int, onSelect func(i int, title string), raw bool, onRawChange func(raw bool)) ui.View

ResponseTabsRow lays out response tabs with a stable Raw checkbox on the right so switching tabs does not change chrome height.

func SaveEditorBytes

func SaveEditorBytes(deps Deps, defaultName string, data []byte)

SaveEditorBytes opens a save dialog and writes data to the chosen path.

func SetEnvForm

func SetEnvForm(th *theme.Theme, id string, set *domain.PostRequestSet, fromOpts []ui.SelectOption, defaultFrom string, markDirty func()) ui.View

func ShowCodeDialog

func ShowCodeDialog(c *ui.Ctx, deps Deps, req *domain.Request)

ShowCodeDialog opens a modal with generated HTTP request code.

func SimpleTitleRow

func SimpleTitleRow(th *theme.Theme, id, name string, onSave func(string), actions ...ui.View) ui.View

SimpleTitleRow is the title row for collection and environment containers: [EditableLabel name] … actions.

func SplitPaneAxis

func SplitPaneAxis(useHorizontalSplit bool) ui.Axis

SplitPaneAxis returns splitter axis from horizontal-split preference.

func StatusLineStyle

func StatusLineStyle(err bool, code int, haveResult bool) ui.Spec

StatusLineStyle returns text style for a response status line.

func StyleCodeEditor added in v0.12.0

func StyleCodeEditor(ed *ui.Editor) *ui.Editor

StyleCodeEditor sets up how a code editor lays out its text: wrapped rows hang one tab stop past their line's indent, so nested JSON keeps its shape, and the line-number gutter is only as wide as its digits.

func SyncParamsFromURL

func SyncParamsFromURL(url string, existingPath []domain.KeyValue) (query []domain.KeyValue, path []domain.KeyValue)

SyncParamsFromURL parses query and path params from a URL, preserving existing path values.

func SyncURLFromParams

func SyncURLFromParams(url string, queryParams []domain.KeyValue) string

SyncURLFromParams rebuilds the URL query string from query params.

func TimelineView

func TimelineView(id string, th *theme.Theme, ctx *ui.Ctx, deps Deps, state *TimelineState, steps []egress.TimelineStep) ui.View

TimelineView renders a waterfall table of steps with a detail card below.

func TriggerRequestPicker

func TriggerRequestPicker(th *theme.Theme, deps Deps, id string, tr *domain.TriggerRequest, markDirty func()) ui.View

func UpdateVariablePreviews

func UpdateVariablePreviews(t *ui.Table, vars []domain.Variable, res *egress.Response)

UpdateVariablePreviews fills preview cells from the last response.

func VarSource

func VarSource(deps Deps, extra func() []vars.Entry) vars.Source

VarSource is the set of variables a container's fields complete and paint: the active environment, the built-in dynamic values, and whatever extra names the container knows about — the ones it writes back from a response, say. extra may be nil.

func VarsFromTable

func VarsFromTable(t *ui.Table) func() []vars.Entry

VarsFromTable reads the response-extraction names out of a variables table, so a request can complete the names it is about to define itself.

Types

type ActionsOpts

type ActionsOpts struct {
	ID string

	Selected *int

	Deps Deps

	Pre        *domain.PreRequest
	Post       *domain.PostRequest
	PreOpts    PrePostOpts
	PostOpts   PrePostOpts
	PreScript  **ui.Editor
	PostScript **ui.Editor
	Preview    string

	// Vars is the response-extractor table. Nil omits the Extract nav item (GraphQL).
	Vars             *ui.Table
	DefaultVarStatus int

	MarkDirty func()
}

ActionsOpts configures the Actions request tab (Before / After / Extract).

type AuthState

type AuthState struct {
	Type         string
	User, Pass   string
	Token        string
	Key, Val     string
	CollectionID string
	AllowInherit bool
	// Vars is what the auth fields complete and paint their {{variable}}
	// placeholders from. The zero value offers nothing.
	Vars vars.Source
}

AuthState holds auth form field values for a container.

func LoadAuthState

func LoadAuthState(auth domain.Auth) AuthState

LoadAuthState reads domain auth into AuthState.

type Catalog

type Catalog interface {
	RequestByID(id string) *domain.Request
	CollectionByID(id string) *domain.Collection
	EnvironmentByID(id string) *domain.Environment
	ReplaceEnvironment(env *domain.Environment)
	Load() error
	AllCollections() []*domain.Collection
	StandaloneRequests() []*domain.Request
	// AllRequests returns every request, with CollectionName set on those
	// in a collection.
	AllRequests() []*domain.Request
	AllEnvironments() []*domain.Environment
}

Catalog is the subset of app catalog a container may query.

type Container

type Container interface {
	ID() string
	Kind() Kind
	Title() string
	Dirty() bool
	Layout(c *ui.Ctx) ui.View
	Close()
	Save() error
	Send()
}

Container is the only editor contract. Protocol-specific UI stays inside each implementation.

type CookiesState

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

CookiesState holds the response Cookies tab: what the server set and what the cookie jar sent.

func (*CookiesState) Close

func (s *CookiesState) Close()

Close releases the tab's widgets.

func (*CookiesState) Set

func (s *CookiesState) Set(deps Deps, res *egress.Response)

Set fills the tab from a response. A nil response clears it.

type Deps

type Deps struct {
	Repo      repository.RepositoryV2
	Catalog   Catalog
	Sender    *sender.Service
	Dialogs   func() *ui.DialogHost
	Files     func() *ui.FileDialog
	Toasts    func() *ui.ToastHost
	Wake      func()
	ActiveEnv func() *domain.Environment
	Report    Reporter
	// Lang creates code editors wired to language servers. Nil means
	// highlighting only.
	Lang *langsrv.Service
	// ManageCookies opens the cookie jar dialog. Nil hides the entry points.
	ManageCookies func()
	// Secrets holds the key that encrypts secret environment values. Nil means
	// values cannot be marked secret.
	Secrets *secret.Manager
	// Clipboard copies text on the user's behalf. Nil hides Copy actions.
	Clipboard func(string)
	// OpenCollection opens a collection in its own tab, for a container that
	// creates one.
	OpenCollection func(*domain.Collection)
	// Tests runs test cases. Nil hides Run.
	Tests *testrun.Runner
}

Deps is everything a container needs to be self-service. Dialogs/Files/Toasts are window services; prefer Report callbacks filled by the app.

func (Deps) ReportDirty

func (d Deps) ReportDirty(dirty bool)

func (Deps) ReportTitle

func (d Deps) ReportTitle(title string)

func (Deps) ShowError

func (d Deps) ShowError(err error)

func (Deps) Toast

func (d Deps) Toast(msg string)

func (Deps) WakeNow

func (d Deps) WakeNow()

type Kind

type Kind string
const (
	KindHTTP       Kind = "request-http"
	KindGRPC       Kind = "request-grpc"
	KindGraphQL    Kind = "request-graphql"
	KindWebSocket  Kind = "request-websocket"
	KindCollection Kind = "collection"
	KindEnv        Kind = "environment"
	KindTestCase   Kind = "testcase"
)

type OpenSpec

type OpenSpec struct {
	Request    *domain.Request
	Collection *domain.Collection
	Env        *domain.Environment
	TestCase   *domain.TestCase
	Deps       Deps
}

OpenSpec is the factory input. Kind is inferred from the non-nil document.

type PrePostOpts

type PrePostOpts struct {
	ID            string
	AllowPython   bool
	AllowSetEnv   bool
	FromOptions   []ui.SelectOption
	DefaultFrom   string
	DefaultStatus int
}

PrePostOpts configures pre/post request UI options.

type Reporter

type Reporter struct {
	Dirty   func(dirty bool)
	Title   func(title string)
	Saved   func()
	Error   func(error)
	Toast   func(msg string)
	Refresh func()
}

Reporter is how a container tells the workspace about its own state.

type SecretsUI

type SecretsUI struct {
	// Revealed reports whether the user asked to see this row's value.
	Revealed func(rowID string) bool
	// ToggleReveal flips that.
	ToggleReveal func(rowID string)
	// OnMarkSecret runs when a row is switched to secret, so the caller can
	// make sure a key exists before the value has to be encrypted.
	OnMarkSecret func(rowID string)
	// Locked reports a row whose value is still encrypted because the key is
	// missing; such a row cannot be edited or revealed.
	Locked func(rowID string) bool
}

SecretsUI is how a table learns about secret rows: which ones the user chose to reveal, and what to do when a row is marked secret.

type TabIconer

type TabIconer interface {
	TabIcon(th *theme.Theme) (icons.Icon, render.Color)
}

TabIconer is implemented by containers whose workspace tab shows an icon before the title, so requests, collections and environments open side by side can be told apart at a glance.

type TimelineState

type TimelineState struct {
	Selected int
	// contains filtered or unexported fields
}

TimelineState holds selection and a retained table for the Timeline tab.

func (*TimelineState) Close

func (t *TimelineState) Close()

Close releases timeline widgets.

func (*TimelineState) Ensure

func (t *TimelineState) Ensure()

Ensure constructs the table once.

func (*TimelineState) EnsureTimelineDetail

func (t *TimelineState) EnsureTimelineDetail()

EnsureTimelineDetail is kept for callers that used the old editor API.

func (*TimelineState) SetSteps

func (t *TimelineState) SetSteps(steps []egress.TimelineStep)

SetSteps refreshes selection, table rows, and detail card from the response timeline.

Directories

Path Synopsis
Package testcase is the editor of a test case: its steps, variables and settings, as a form or as YAML, with the results of its last run.
Package testcase is the editor of a test case: its steps, variables and settings, as a form or as YAML, with the results of its last run.
Package websocket is the editor for WebSocket requests: a connection the user opens, sends messages on, and watches.
Package websocket is the editor for WebSocket requests: a connection the user opens, sends messages on, and watches.

Jump to

Keyboard shortcuts

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