api

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package api hosts the HTTP API layer that wraps the clanker agent.

Phase 4 (per the planning doc) — exposes Tencent Cloud inventory and helper endpoints as JSON so the React/Vite dashboard (Phase 5+) can drive the agent without shelling out to the CLI.

The server uses stdlib net/http (Go 1.22+ pattern routing) — no third party router needed at this scale.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetVersion

func SetVersion(v string)

SetVersion sets the version string returned by the /api/v1/version endpoint. Called once from cmd/server.go after main() initialises cmd.Version.

Types

type ApplyRecord

type ApplyRecord struct {
	ID               int64     `json:"id"`
	StartedAt        time.Time `json:"started_at"`
	Provider         string    `json:"provider"`
	Status           string    `json:"status"` // "ok" or "error"
	Duration         string    `json:"duration"`
	Destroyer        bool      `json:"destroyer"`
	CommandCount     int       `json:"command_count"`
	DestructiveCount int       `json:"destructive_count"`
	Summary          string    `json:"summary,omitempty"`
	Question         string    `json:"question,omitempty"`
	Error            string    `json:"error,omitempty"`
	Output           string    `json:"output,omitempty"`
	OutputTruncated  bool      `json:"output_truncated,omitempty"`
}

ApplyRecord is what /api/v1/maker/history returns for each past apply.

Output is truncated server-side so the list endpoint stays cheap. For full output a future endpoint can fetch by ID.

type Config

type Config struct {
	Addr         string // listen address, e.g. ":8080"
	Token        string // bearer token; required unless Insecure is true
	Insecure     bool   // explicit opt-in to running without auth; refused otherwise
	CORSOrigin   string // value for Access-Control-Allow-Origin; defaults to http://localhost:4173 (the bundled dashboard)
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	Debug        bool
}

Config controls how the HTTP server is bound and how requests are authorised. A missing Token aborts startup unless Insecure is set explicitly — see Server.Run.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps an *http.Server plus the routes the API exposes. Build it with New and start with Run; Run blocks until ctx is cancelled.

func New

func New(cfg Config, logger *log.Logger) *Server

New constructs a Server with the standard route set. Call Run to start.

func (*Server) Run

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

Run starts the HTTP server and blocks until ctx is cancelled or ListenAndServe returns an error.

Jump to

Keyboard shortcuts

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