diragent

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 22 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 diragent implements the client part of the directory agent protocol. It handles connecting to the server via websocket, authentication, and relaying messages from the server to a child process (implemented by RunWorker) and back.

Index

Constants

View Source
const (
	// DefaultMaxConcurrentRequests is the default number of worker/connection lanes.
	DefaultMaxConcurrentRequests = 3
	// MaximumConcurrentRequests is the maximum supported number of worker/connection lanes.
	MaximumConcurrentRequests = 16
)

🤖

Variables

This section is empty.

Functions

func NewLogger added in v0.1.30

func NewLogger(w io.Writer, format LogFormat) *slog.Logger

NewLogger builds a logger that writes every record to w in the given format, regardless of level. Use it for a process whose stdout is reserved for something other than log output (such as a directory agent worker, whose stdout carries the JSON request/response protocol), so all of its own messages -- errors included -- have to share the one stream it can safely write to.

func RunWorker

func RunWorker(ctx context.Context, provider directory.Provider, logger *slog.Logger) error

RunWorker implements the worker process for a directory agent. It handles accepting and processing requests from the server. It returns when ctx is canceled or when the parent closes stdin.

logger is used only for conditions that have nowhere else to go, such as a provider panic: the worker's stdout already carries the JSON request/response protocol, so its own messages (errors included) share its stderr. A nil logger defaults to plain text on os.Stderr. 🤖

func SelfArgv added in v0.1.28

func SelfArgv() ([]string, error)

SelfArgv returns the absolute path of the current executable followed by its original command-line arguments. The result can be passed to exec.Command to start the same command directly, without a shell or executable-path lookup.

Types

type LogFormat added in v0.1.30

type LogFormat string

LogFormat selects how a directory agent process renders its own log messages.

const (
	// LogFormatText renders log messages as human-readable text. This is the default.
	LogFormatText LogFormat = "text"
	// LogFormatJSON renders log messages as one structured JSON object per line.
	LogFormatJSON LogFormat = "json"
)

func ParseLogFormat added in v0.1.30

func ParseLogFormat(value string) (LogFormat, error)

ParseLogFormat validates a --log-format flag value. An empty string is accepted and normalized to LogFormatText.

type Service

type Service struct {
	Server    string
	AuthToken string
	DirID     string

	// MaxConcurrentRequests sets the number of worker/connection lanes.
	// Zero means one lane.
	MaxConcurrentRequests int // 🤖

	// Command starts the worker through the platform shell: cmd.exe /c on Windows
	// or /bin/sh -c elsewhere. Use it for operator-supplied commands that may contain
	// shell syntax. It is ignored when Argv is non-empty.
	Command string

	// Argv starts the worker directly without a shell. Argv[0] is the executable
	// and the remaining elements are passed as individual arguments. Use it for
	// programmatically constructed invocations so argument boundaries are preserved.
	// Argv takes precedence over Command.
	Argv []string

	Env        map[string]string
	Stdout     io.Writer // 🤖 defaults to os.Stdout; carries the agent's own info/debug messages
	Stderr     io.Writer
	HTTPClient *http.Client
	Verbose    bool

	// ListenStatus, if non-empty, is the address (e.g. "0.0.0.0:8000") for an HTTP
	// server exposing a Kubernetes-style "/ready" liveness/readiness endpoint. It is
	// disabled when empty. 🤖
	ListenStatus string

	// LogFormat selects how the agent renders its own log messages: text
	// (the default) or json. 🤖
	LogFormat LogFormat
	// contains filtered or unexported fields
}

Service runs the parent process for the directory agent. It connects to the server and relays messages between the server (via websocket) and the child process (via stdin/stdout).

func (*Service) Run

func (s *Service) Run(ctx context.Context) error

Run supervises independent worker/connection lanes until cancellation or worker failure. Websocket failures reconnect only the affected lane. 🤖

Jump to

Keyboard shortcuts

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