api

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.1.0"

Version is set by the main package at startup.

Functions

func BearerAuth

func BearerAuth(token string) func(http.Handler) http.Handler

BearerAuth returns middleware that validates a Bearer token on every request. When token is empty, all requests are allowed (auth disabled).

Types

type ConfigProvider

type ConfigProvider interface {
	PluginConfig(name string) map[string]any
	SetPluginConfig(plugin, key string, value any)
	Save(path string) error
	Path() string
}

ConfigProvider abstracts config persistence so the API can update plugin config and save to disk without importing the config package.

type ErrorBody

type ErrorBody struct {
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Details interface{} `json:"details"`
}

ErrorBody holds error details.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorBody `json:"error"`
}

ErrorResponse is the standard error envelope.

type JobTriggerer

type JobTriggerer interface {
	TriggerJob(id string) error
	TriggerJobAsync(id string) error
	JobExists(id string) bool
	Reschedule(id, cron string) error
	LatestRun(id string) *scheduler.JobRun
	ListRuns(id string, limit, offset int) ([]storage.RunRecord, error)
}

JobTriggerer is satisfied by the scheduler to trigger jobs by ID.

type Server

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

Server wraps an HTTP server that serves the CM Core API.

func NewServer

func NewServer(host string, port int, sched JobTriggerer, cfg ConfigProvider, authToken string, webHandler http.Handler) *Server

NewServer creates a new API server with core and plugin routes mounted. When authToken is non-empty, all endpoints except /api/v1/health require a valid Bearer token. If webHandler is non-nil it is mounted at the root for the browser-based dashboard.

func (*Server) Err

func (s *Server) Err() <-chan error

Err returns a read-only channel that receives fatal start-up errors.

func (*Server) Shutdown

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

Shutdown gracefully stops the API server.

func (*Server) Start

func (s *Server) Start()

Start begins listening in a goroutine. Call Shutdown to stop. Fatal start-up errors (e.g. port in use) are sent to Err().

Jump to

Keyboard shortcuts

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