Documentation
¶
Overview ¶
Package http provides HTTP API for contextd.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
}
HealthResponse is the response body for GET /health.
type ScrubRequest ¶
type ScrubRequest struct {
Content string `json:"content"`
}
ScrubRequest is the request body for POST /api/v1/scrub.
type ScrubResponse ¶
type ScrubResponse struct {
Content string `json:"content"`
FindingsCount int `json:"findings_count"`
}
ScrubResponse is the response body for POST /api/v1/scrub.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides HTTP endpoints for contextd.
Example ¶
ExampleServer demonstrates how to create and start the HTTP server.
package main
import (
"context"
"fmt"
"time"
httpserver "github.com/fyrsmithlabs/contextd/internal/http"
"github.com/fyrsmithlabs/contextd/internal/secrets"
"github.com/fyrsmithlabs/contextd/internal/services"
"go.uber.org/zap"
)
func main() {
// Create a scrubber with default configuration
scrubber, err := secrets.New(nil)
if err != nil {
panic(err)
}
// Create a services registry with minimal configuration
// In a real application, you would initialize all services
registry := services.NewRegistry(services.Options{
Scrubber: scrubber,
// Other services would be initialized here
})
// Create logger
logger, _ := zap.NewProduction()
defer logger.Sync()
// Configure the server
cfg := &httpserver.Config{
Host: "localhost",
Port: 9090,
}
// Create the server
server, err := httpserver.NewServer(registry, logger, cfg)
if err != nil {
panic(err)
}
// Start server in background
go func() {
if err := server.Start(); err != nil {
logger.Error("server error", zap.Error(err))
}
}()
// Give server time to start
time.Sleep(100 * time.Millisecond)
// Graceful shutdown
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
logger.Error("shutdown error", zap.Error(err))
}
fmt.Println("Server started and stopped successfully")
}
Output: Server started and stopped successfully
type StatusCounts ¶ added in v0.3.0
StatusCounts contains count information for various resources.
type StatusResponse ¶ added in v0.3.0
type StatusResponse struct {
Status string `json:"status"`
Services map[string]string `json:"services"`
Counts StatusCounts `json:"counts"`
}
StatusResponse is the response body for GET /api/v1/status.
type ThresholdRequest ¶
type ThresholdRequest struct {
ProjectID string `json:"project_id"`
SessionID string `json:"session_id"`
Percent int `json:"percent"`
}
ThresholdRequest is the request body for POST /api/v1/threshold.
type ThresholdResponse ¶
type ThresholdResponse struct {
CheckpointID string `json:"checkpoint_id"`
Message string `json:"message"`
}
ThresholdResponse is the response body for POST /api/v1/threshold.
Click to show internal directories.
Click to hide internal directories.