Documentation
¶
Overview ¶
Package version registers a stable JSON version endpoint.
NewHandler accepts a Config with path and Info values. Register the handler on a router that supports method-based route registration, or use Handler directly when composing with net/http.
Purpose: See the package summary above. Import: `github.com/aatuh/api-toolkit/v4/endpoints/version`. Example: See docs/api-reference.md for package example links and docs/cookbook.md for task recipes. Errors: Constructors, parsers, and handlers return or write documented errors according to their signatures; packages with plain data types do not add hidden error channels. Concurrency: Treat configured middleware and helpers as immutable after construction; request and response values remain request-scoped unless a type documents stronger guarantees. Stability: Stable core API under VERSIONING.md and scripts/apicheck.sh. When not to use: Prefer net/http, application-owned types, or narrower helpers when this package contract is not needed.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler wires the version endpoint.
func NewHandler ¶
NewHandler constructs a Handler from the provided config.
Example ¶
package main
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"github.com/aatuh/api-toolkit/v4/endpoints/version"
)
func main() {
handler := version.NewHandler(version.Config{
Info: version.Info{Version: "1.2.3", Commit: "abc123", Date: "2026-06-05"},
})
recorder := httptest.NewRecorder()
req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/version", nil)
handler.Handler().ServeHTTP(recorder, req)
fmt.Println(recorder.Code)
}
Output: 200
func (*Handler) Handler ¶
func (h *Handler) Handler() http.HandlerFunc
Handler returns an HTTP handler that writes the version info JSON.
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(router interface { Get(pattern string, h http.HandlerFunc) })
RegisterRoutes mounts the handler on the router.
func (*Handler) RegisterRoutesTo ¶
func (h *Handler) RegisterRoutesTo(router RouteRegistrar)
RegisterRoutesTo mounts the handler on a minimal route registrar.
type Info ¶
type Info struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"date"`
}
Info describes the build metadata exposed by the version endpoint.
type RouteRegistrar ¶
type RouteRegistrar interface {
Get(pattern string, h http.HandlerFunc)
}
RouteRegistrar is the minimal route registration capability used by Handler.