Documentation
¶
Overview ¶
Package shared provides configuration, logging, error helpers, and constants used across dployrd. Shared, cross-cutting utilities live here to avoid duplication in other packages, including config for sync intervals and task deduplication TTLs.
Config fields related to container builds:
RegistryURL: container registry to push images to (e.g. "registry.digitalocean.com/my-registry" or "localhost:5000"). Set via REGISTRY_URL in config.toml.
RegistryAuth: base64-encoded JSON credentials for docker login ({"username":"…","password":"…"}). Set via REGISTRY_AUTH in config.toml. Leave empty for unauthenticated or credential-helper-backed registries.
Index ¶
- Constants
- Variables
- func ConvertMapToStrings(m map[string]any) map[string]string
- func EnrichContext(ctx context.Context) context.Context
- func Exec(ctx context.Context, cmd string, workDir string) error
- func ExecWithOptions(ctx context.Context, cmd string, workDir string, useVfox bool) error
- func GetToken() (string, error)deprecated
- func LoadTomlFile(path string) error
- func LogErrF(name, dir string, err error) error
- func LogInfoF(name, dir, message string) error
- func LogWarnF(name, dir, message string) error
- func RequestFromContext(ctx context.Context) (string, error)
- func RequestID(ctx context.Context) string
- func SanitizeSyncInterval(v time.Duration) time.Duration
- func TraceFromContext(ctx context.Context) (string, error)
- func TraceID(ctx context.Context) string
- func User(ctx context.Context) *store.User
- func UserFromContext(ctx context.Context) (*store.User, error)
- func WithRequest(ctx context.Context, id string) context.Context
- func WithTrace(ctx context.Context, id string) context.Context
- func WithUser(ctx context.Context, id string) context.Context
- func WriteError(w http.ResponseWriter, status int, code, message string, details any)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type AppError
- type Config
- type ContextKey
- type ContextMeta
- type ErrorCode
- type ErrorDescriptor
- type ErrorResponse
- type Logger
- type Semaphore
Constants ¶
const (
ServerHome string = "/usr/local/bin/dployr"
)
Variables ¶
var Errors = struct { Request struct { MissingParams ErrorDescriptor BadRequest ErrorDescriptor MethodNotAllowed ErrorDescriptor } Auth struct { Unauthorized ErrorDescriptor Forbidden ErrorDescriptor } Resource struct { NotFound ErrorDescriptor } Instance struct { RegistrationFailed ErrorDescriptor } Runtime struct { InternalServer ErrorDescriptor } }{ Request: struct { MissingParams ErrorDescriptor BadRequest ErrorDescriptor MethodNotAllowed ErrorDescriptor }{ MissingParams: ErrorDescriptor{Code: ErrorRequestMissingParams, HTTPStatus: http.StatusBadRequest, Message: "Missing required parameters"}, BadRequest: ErrorDescriptor{Code: ErrorRequestBadRequest, HTTPStatus: http.StatusBadRequest, Message: "Bad request"}, MethodNotAllowed: ErrorDescriptor{Code: ErrorRequestMethodNotAllowed, HTTPStatus: http.StatusMethodNotAllowed, Message: "Method not allowed"}, }, Auth: struct { Unauthorized ErrorDescriptor Forbidden ErrorDescriptor }{ Unauthorized: ErrorDescriptor{Code: ErrorAuthUnauthorized, HTTPStatus: http.StatusUnauthorized, Message: "Unauthorized"}, Forbidden: ErrorDescriptor{Code: ErrorAuthForbidden, HTTPStatus: http.StatusForbidden, Message: "Forbidden"}, }, Resource: struct { NotFound ErrorDescriptor }{ NotFound: ErrorDescriptor{Code: ErrorResourceNotFound, HTTPStatus: http.StatusNotFound, Message: "Resource not found"}, }, Runtime: struct { InternalServer ErrorDescriptor }{ InternalServer: ErrorDescriptor{Code: ErrorRuntimeInternalServer, HTTPStatus: http.StatusInternalServerError, Message: "Internal server error"}, }, Instance: struct { RegistrationFailed ErrorDescriptor }{ RegistrationFailed: ErrorDescriptor{Code: ErrorInstanceRegistrationFailed, HTTPStatus: http.StatusInternalServerError, Message: "Instance registration failed"}, }, }
Errors is a structured catalog of application errors that are currently used across the HTTP handlers.
Functions ¶
func ConvertMapToStrings ¶ added in v0.5.0
ConvertMapToStrings converts a map[string]any to map[string]string. This is useful for environment variables and secrets which must be strings. Supports string, number (int, int64, float64), and boolean values.
func ExecWithOptions ¶ added in v0.4.11
func LoadTomlFile ¶
func SanitizeSyncInterval ¶
SanitizeSyncInterval clamps a duration to safe sync bounds.
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string, details any)
Types ¶
type Config ¶
type Config struct {
Address string
Port int
MaxWorkers int
BaseURL string
InstanceID string
SyncInterval time.Duration
WSCertPath string
WSMaxMessageSize int64
TaskDedupTTL time.Duration
Role store.NodeRole
RegistryURL string
RegistryAuth string
BuildSlots int
BuildMemory int
ContainerMemory int
ContainerCPU int
ContainerStorage int
LogMaxChunkBytes int64
LogBatchSize int
LogBatchTimeout time.Duration
LogMaxBatchTimeout time.Duration
LogPollInterval time.Duration
LogMaxFileReadBytes int64
LogMaxStreams int
LogEntryJSONOverhead int64
}
func LoadConfig ¶
type ContextKey ¶
type ContextKey string
const ( CtxUserIDKey ContextKey = "user_id" CtxRequestIDKey ContextKey = "request_id" CtxTraceIDKey ContextKey = "trace_id" )
type ContextMeta ¶
func Meta ¶
func Meta(ctx context.Context) *ContextMeta
type ErrorCode ¶
type ErrorCode string
ErrorCode is an identifier for an error that can be surfaced to clients and logged across services.
const ( // Request-level errors ErrorRequestMissingParams ErrorCode = "request.missing_params" ErrorRequestBadRequest ErrorCode = "request.bad_request" ErrorRequestMethodNotAllowed ErrorCode = "request.method_not_allowed" // Auth errors ErrorAuthForbidden ErrorCode = "auth.forbidden" // Resource errors ErrorResourceNotFound ErrorCode = "resource.not_found" // Runtime / internal errors ErrorRuntimeInternalServer ErrorCode = "runtime.internal_server_error" ErrorInstanceRegistrationFailed ErrorCode = "instance.registration_failed" )
type ErrorDescriptor ¶
ErrorDescriptor defines a specific error, with its code, HTTP status and human-readable message. It's the source of truth for HTTP responses and OpenAPI error objects.
type ErrorResponse ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps slog with multi-sink (stdout + file) and context-aware logging.
func LogWithContext ¶
LogWithContext is a legacy helper; use logger.WithContext(ctx) instead. Kept for backward compatibility during migration.
func NewLogger ¶
func NewLogger() *Logger
NewLogger creates a unified logger that writes structured JSON to both stdout and a file. Log files are rotated every 24 hours or when they exceed 300MB, whichever comes first.
type Semaphore ¶ added in v0.5.0
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore provides context-aware concurrency limiting.
func NewSemaphore ¶ added in v0.5.0
NewSemaphore creates a new semaphore with the given max concurrent acquisitions.