Documentation
¶
Index ¶
- Constants
- Variables
- func NewServeMux(client *AMQPClient, aliases []AliasConfig) http.Handler
- func RenderConfig(ctx context.Context, path string) ([]byte, error)
- func RunCLI(ctx context.Context) error
- func RunServer(ctx context.Context, cfg *Config) error
- type AMQPClient
- type AliasConfig
- type AliasResponseConfig
- type CLI
- type ClientOptions
- type ClientPublishCmd
- type ClientRPCCmd
- type Config
- type Metrics
- type PublishParams
- type RenderCmd
- type RunCmd
- type TimeoutError
- type ValidateCmd
- type ValidationError
Constants ¶
const ( // AliasMethodPublish and AliasMethodRPC are the allowed values for AliasConfig.Method. AliasMethodPublish = "publish" AliasMethodRPC = "rpc" )
Variables ¶
var Version = "v0.1.2"
Functions ¶
func NewServeMux ¶
func NewServeMux(client *AMQPClient, aliases []AliasConfig) http.Handler
NewServeMux creates the HTTP handler with all routes.
func RenderConfig ¶
RenderConfig evaluates the config file and returns pretty-printed JSON.
Types ¶
type AMQPClient ¶
type AMQPClient struct {
// contains filtered or unexported fields
}
AMQPClient handles AMQP connections and operations.
func NewAMQPClient ¶
func NewAMQPClient(cfg *Config, tracer trace.Tracer, metrics *Metrics) *AMQPClient
NewAMQPClient creates a new AMQPClient.
func (*AMQPClient) Ping ¶
func (c *AMQPClient) Ping(ctx context.Context) error
Ping tests the RabbitMQ connection using the base URL (no credentials).
func (*AMQPClient) Publish ¶
func (c *AMQPClient) Publish(ctx context.Context, params *PublishParams, body []byte) error
Publish connects to RabbitMQ and publishes a message.
func (*AMQPClient) RPC ¶
func (c *AMQPClient) RPC(ctx context.Context, params *PublishParams, body []byte) (*amqp.Delivery, error)
RPC connects to RabbitMQ, publishes a message, and waits for a response.
type AliasConfig ¶
type AliasConfig struct {
Path string `json:"path"`
Method string `json:"method"` // "publish" or "rpc"
// AMQP parameters — same fields as PublishParams.
// HTTP request headers can override these if provided.
Username string `json:"username"`
Password string `json:"password"`
Exchange string `json:"exchange"`
RoutingKey string `json:"routing_key"`
VHost string `json:"vhost"`
DeliveryMode *uint8 `json:"delivery_mode"`
ContentType string `json:"content_type"`
Timeout time.Duration `json:"timeout"`
Headers map[string]string `json:"headers"`
// Response customization for alias endpoints.
Response *AliasResponseConfig `json:"response,omitempty"`
}
AliasConfig defines a custom HTTP path that maps to a publish or rpc call with pre-configured AMQP parameters.
type AliasResponseConfig ¶ added in v0.0.3
type AliasResponseConfig struct {
Status int `json:"status,omitempty"`
ContentType string `json:"content_type,omitempty"`
Body any `json:"body,omitempty"`
}
AliasResponseConfig customizes the HTTP response for alias endpoints.
type CLI ¶
type CLI struct {
Config string `kong:"short='c',env='AMQP_GATEWAY_CONFIG',help='Config file path (Jsonnet/JSON)'"`
LogLevel string `kong:"default='info',enum='debug,info,warn,error',env='AMQP_GATEWAY_LOG_LEVEL',help='Log level'"`
Run RunCmd `cmd:"" default:"1" help:"Run the gateway server"`
Validate ValidateCmd `cmd:"" help:"Validate config"`
Render RenderCmd `cmd:"" help:"Render config as JSON to stdout"`
Publish ClientPublishCmd `cmd:"" help:"Publish a message via HTTP"`
RPC ClientRPCCmd `cmd:"" help:"Send an RPC request via HTTP"`
Version kong.VersionFlag `help:"Show version"`
}
CLI represents the command-line interface.
type ClientOptions ¶
type ClientOptions struct {
URL string `kong:"required,arg,help='Gateway URL (e.g. http://localhost:8080)'"`
User string `kong:"short='u',env='AMQP_GATEWAY_USER',help='Username for Basic auth'"`
Password string `kong:"short='p',env='AMQP_GATEWAY_PASSWORD',help='Password for Basic auth'"`
Exchange string `kong:"name='exchange',help='AMQP exchange'"`
RoutingKey string `kong:"name='routing-key',help='AMQP routing key'"`
VHost string `kong:"name='vhost',help='AMQP vhost'"`
DeliveryMode string `kong:"name='delivery-mode',help='AMQP delivery mode (1=transient, 2=persistent)'"`
MessageID string `kong:"name='message-id',help='AMQP message ID'"`
CorrelationID string `kong:"name='correlation-id',help='AMQP correlation ID'"`
Expiration string `kong:"name='expiration',help='AMQP expiration'"`
ContentType string `kong:"name='content-type',help='Content-Type header'"`
Timeout time.Duration `kong:"name='timeout',help='RPC timeout (e.g. 5s, 500ms)'"`
Headers map[string]string `kong:"name='header',short='H',help='Custom AMQP headers (key=value)'"`
Body string `kong:"name='body',xor='body',help='Message body string'"`
BodyFile string `kong:"name='body-file',xor='body',help='Read message body from file (- for stdin)'"`
}
ClientOptions holds common options for publish and rpc client commands.
type ClientPublishCmd ¶
type ClientPublishCmd struct {
ClientOptions `kong:"embed"`
}
ClientPublishCmd publishes a message via the gateway HTTP API.
type ClientRPCCmd ¶
type ClientRPCCmd struct {
ClientOptions `kong:"embed"`
}
ClientRPCCmd sends an RPC request via the gateway HTTP API.
type Config ¶
type Config struct {
AMQPURL string `json:"amqp_url"`
ListenAddr string `json:"listen_addr"`
ShutdownTimeout time.Duration `json:"shutdown_timeout"`
MaxConnsPerUser int `json:"max_conns_per_user"`
ConnTTL time.Duration `json:"conn_ttl"`
Aliases []AliasConfig `json:"aliases"`
}
Config represents the application configuration.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds OpenTelemetry metric instruments.
type PublishParams ¶
type PublishParams struct {
Username string
Password string
Exchange string
RoutingKey string
VHost string
DeliveryMode uint8
MessageID string
CorrelationID string
Expiration string
ContentType string
Headers amqp.Table
Timeout time.Duration
}
PublishParams holds the parsed AMQP parameters from HTTP headers.
func ParsePublishParams ¶
func ParsePublishParams(r *http.Request) (*PublishParams, error)
ParsePublishParams extracts AMQP parameters from HTTP request headers.
type TimeoutError ¶
TimeoutError represents an RPC timeout.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type ValidationError ¶
ValidationError represents a header validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string