endpoints

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package endpoints provides types and utilities for defining and registering HTTP endpoints.

Use this package when building HTTP APIs that require structured endpoint path registration with validation. It enables grouping middleware with handlers, validating endpoint paths at registration time, and organizing endpoints through a builder pattern.

The package supports parameterized paths using curly brace syntax (e.g., "/users/{id}") and validates that paths follow correct formatting conventions. Types implementing the EndpointHandler interface can register their endpoints with a shared builder, making it easy to compose endpoints from multiple sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is used in the EndpointHandler's visitor to set paths to handlers.

func NewBuilder

func NewBuilder() *Builder

NewBuilder allocates and sets default values in a Builder.

func (*Builder) API

func (builder *Builder) API() map[Path]map[Method]*Endpoint

API returns a map of Path to Method to Endpoint.

func (*Builder) MustRegister

func (builder *Builder) MustRegister(path Path, method Method, endpoint *Endpoint)

MustRegister assigns a Path and Method to a Endpoint. This function does validation to ensure duplicates are not registered. If the path and method is already registered, this function panics.

type Endpoint

type Endpoint struct {
	Middleware []middleware.Middleware
	Handler    http.HandlerFunc
}

Endpoint encapsulates middleware and an HTTP handler for request processing.

type EndpointHandler

type EndpointHandler interface {
	RegisterEndpoints(builder *Builder)
}

EndpointHandler is implemented by types that register HTTP endpoints.

type Method

type Method string

Method is a command used by a client to indicate the desired action to be performed on a specified resource within a server as part of the HTTP protocol.

type Path

type Path string

Path specifies the particular resource on the server.

Jump to

Keyboard shortcuts

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