api

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package api serves HTTP. The server is a singleton with a lifecycle. A handler type covers one resource, with a method per route; it is Scoped when it needs the request, and built in the request scope the dihttp middleware opens, or a plain singleton when it does not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module(s *di.Scope)

Module registers the request-scoped values, the handlers and the server, with the hooks that bind, drain and close it.

func NewServer

func NewServer(cfg config.Config, mw dihttp.Middleware) *http.Server

NewServer builds the routes. Each one resolves its handler from the request scope the middleware opens; dihttp.Module provides the middleware.

Types

type Caller

type Caller struct{ Name string }

Caller is who is making the request. It depends on the *http.Request, which only a request scope provides.

func NewCaller

func NewCaller(r *http.Request) *Caller

type Health added in v0.13.0

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

Health needs nothing from the request, so it is an ordinary singleton.

func NewHealth added in v0.13.0

func NewHealth(db *storage.DB) *Health

func (*Health) Check added in v0.13.0

func (h *Health) Check(w http.ResponseWriter, r *http.Request)

type Users added in v0.13.0

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

Users is built once per request, from singletons and request-scoped values alike, and serves every route about users.

func NewUsers added in v0.13.0

func NewUsers(store storage.Store, m *mail.Mailer, caller *Caller) *Users

func (*Users) Greet added in v0.13.0

func (u *Users) Greet(w http.ResponseWriter, r *http.Request)

func (*Users) Show added in v0.13.0

func (u *Users) Show(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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