server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package server provides the HTTP server exposing /healthz, /metrics, and the git webhook endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildInfo

type BuildInfo struct {
	Version   string
	Commit    string
	BuildDate string
}

BuildInfo holds version metadata injected at link time.

type DiffEntry

type DiffEntry struct {
	JobID       string `json:"job_id"`
	HCLFile     string `json:"hcl_file,omitempty"`
	DiffType    string `json:"diff_type"`
	Detail      string `json:"detail"`
	ApplyAction string `json:"apply_action,omitempty"`
}

DiffEntry is one element of HealthResponse.Diffs.

type DiffSource

type DiffSource interface {
	Diffs() ([]nomad.JobDiff, time.Time, string)
	SelectedJobs() ([]nomad.SelectedJob, time.Time, string)
	// Updates returns a snapshot of the GitOps update queue.
	Updates() []nomad.JobUpdate
	// Ready reports whether at least one diff check has completed.
	Ready() bool
}

DiffSource is satisfied by *nomad.Differ.

type GitStatusSource

type GitStatusSource interface {
	Trigger()
	Status() (lastCommit string, lastUpdate time.Time)
	// Ready reports whether the initial git clone has completed.
	Ready() bool
}

GitStatusSource is satisfied by *gitwatch.Watcher.

type HealthResponse

type HealthResponse struct {
	Status     string      `json:"status"`
	Message    string      `json:"message,omitempty"`
	DiffCount  int         `json:"diff_count"`
	Diffs      []DiffEntry `json:"diffs"`
	LastCheck  string      `json:"last_check,omitempty"`
	GitCommit  string      `json:"git_commit,omitempty"`
	GitUpdated string      `json:"git_updated,omitempty"`
}

HealthResponse is the JSON body returned by /healthz.

type Server

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

Server holds the HTTP mux and all dependencies.

func New

func New(cfg *config.Config, diffs DiffSource, git GitStatusSource, info BuildInfo) *Server

New creates a Server that registers Prometheus metrics into the default registry.

func NewWithRegistry

func NewWithRegistry(cfg *config.Config, diffs DiffSource, git GitStatusSource, info BuildInfo, reg prometheus.Registerer) *Server

NewWithRegistry creates a Server with a custom Prometheus Registerer. Useful in tests to avoid duplicate-registration panics when creating multiple servers.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the underlying http.Handler, useful for testing without a real listener.

func (*Server) Run

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

Run starts the HTTP server and blocks until ctx is cancelled.

Jump to

Keyboard shortcuts

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