Documentation
¶
Index ¶
- Constants
- func CaptureOutput(f func()) (stdout, stderr string)
- func Error(format string, args ...interface{})
- func Errorf(err error)
- func Fatalf(format string, args ...interface{})
- func Info(format string, args ...interface{})
- func JSON(v interface{}, pretty bool) error
- func KeyValue(pairs map[string]string)
- func Print(format string, args ...interface{})
- func Success(format string, args ...interface{})
- func Table(headers []string, rows [][]string)
- func TestDB(t *testing.T, composeFile string) *sql.DB
- func Warning(format string, args ...interface{})
- type APIDefinition
- type APIRegistry
- type APIStatus
- type ApiProvider
- type CLI
- type CanonicalEvent
- type Config
- type Context
- type HTTPClient
- type Option
- type Response
- type State
- type SubcommandProvider
Constants ¶
const ( ColorReset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorGray = "\033[90m" )
Color codes for terminal output
Variables ¶
This section is empty.
Functions ¶
func CaptureOutput ¶
func CaptureOutput(f func()) (stdout, stderr string)
CaptureOutput captures stdout and stderr for testing
func Error ¶
func Error(format string, args ...interface{})
Error prints an error message in red to stderr
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf prints an error message in red to stderr and exits with code 1
func Success ¶
func Success(format string, args ...interface{})
Success prints a success message in green
func TestDB ¶
TestDB opens a database connection derived from a schemaf compose file. It reads the x-schemaf metadata (project name, db-port, dev-db-pass) from the resolved compose files so tests never need to hardcode credentials or set DATABASE_URL manually.
Falls back to DATABASE_URL if set (CI / external Postgres). Registers t.Cleanup to close the connection automatically.
Example:
db := cli.TestDB(t, "../compose/test.yml")
Types ¶
type APIDefinition ¶
type APIDefinition struct {
Name string // e.g. "foo"
Description string // Human-readable description of the API
URLDefault string // base url of the API, e.g. "http://127.0.0.1:8080/api"
URLConfigKey string // key in config to customize URL, e.g. "foo.api.url"
HasEvents bool // Whether this API has standardized /events endpoint
HasHealth bool // Whether this API has a standardized /health endpoint
HasStatus bool // Whether this API has a standardized /status endpoint
EventsPath *string // Path to events endpoint, default: "/events"
HealthPath *string // Path to health endpoint, default: "/health"
StatusPath *string // Path to status endpoint, default: "/status"
}
APIDefinition defines a registered API
func (*APIDefinition) CheckHealth ¶
func (a *APIDefinition) CheckHealth(url string, timeout time.Duration) *APIStatus
CheckHealth checks the health of an API
type APIRegistry ¶
type APIRegistry struct {
// contains filtered or unexported fields
}
APIRegistry holds registered APIs and their configuration
func (*APIRegistry) GetAll ¶
func (r *APIRegistry) GetAll() []*APIDefinition
GetAll returns all registered APIs sorted by name
func (*APIRegistry) Register ¶
func (r *APIRegistry) Register(api APIDefinition)
Register adds an API to the registry
type APIStatus ¶
type APIStatus struct {
Name string `json:"name"`
URL string `json:"url"`
Status string `json:"status"` // "healthy", "down", "unknown"
ResponseTime int64 `json:"response_ms"` // Response time in milliseconds
Error string `json:"error,omitempty"`
}
APIStatus represents the health status of an API
type ApiProvider ¶
type ApiProvider func() []APIDefinition
ApiProvider registers APIs with the API registry
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI represents the composable CLI framework
func (*CLI) AddApis ¶
func (c *CLI) AddApis(apiProviders ...ApiProvider) *CLI
func (*CLI) AddSubcommands ¶
func (c *CLI) AddSubcommands(providers ...SubcommandProvider) *CLI
AddSubcommands mounts subcommand providers to this CLI
func (*CLI) Subcommand ¶
Subcommand creates and returns a new subcommand group
type CanonicalEvent ¶
type CanonicalEvent struct {
Event string `json:"event"`
TS string `json:"ts"`
Source string `json:"source"`
User string `json:"user"`
Payload map[string]interface{} `json:"payload"`
}
CanonicalEvent represents the standardized Schemaf event format
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config handles config.toml (static configuration)
func (*Config) GetStringSlice ¶
GetStringSlice returns a string slice from config
type Context ¶
type Context struct {
APIs *APIRegistry
Config *Config
State *State
HTTPClient *HTTPClient
HomeDir string
Verbose bool
}
Context provides access to framework features
func NewTestContext ¶
func NewTestContext() *Context
NewTestContext creates a Context for testing with in-memory config/state
func (*Context) SetTestConfig ¶
SetTestConfig sets config values for testing
func (*Context) SetTestState ¶
SetTestState sets state values for testing
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient provides HTTP request utilities
func NewHTTPClient ¶
func NewHTTPClient(verbose bool) *HTTPClient
NewHTTPClient creates a new HTTP client with default settings
func (*HTTPClient) Get ¶
func (c *HTTPClient) Get(url string) (*Response, error)
Get performs a GET request
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(url string, body interface{}) (*Response, error)
Post performs a POST request with JSON body
func (*HTTPClient) WithHeader ¶
func (c *HTTPClient) WithHeader(key, value string) *HTTPClient
WithHeader sets a header for all requests
func (*HTTPClient) WithTimeout ¶
func (c *HTTPClient) WithTimeout(seconds int) *HTTPClient
WithTimeout sets the HTTP client timeout in seconds
type Response ¶
Response represents an HTTP response
type State ¶
type State struct {
// contains filtered or unexported fields
}
State handles state.toml (dynamic runtime state - extensible)
type SubcommandProvider ¶
SubcommandProvider returns a slice of commands to be mounted Providers receive a Context with access to config, state, and utilities