api

package
v0.0.0-...-c05fae0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api contains the HTTP endpoints of the Karman API. We use the github.com/go-chi/chi router. Every collection of endpoints is implemented as a Handler type that exposes a Router function compatible with Chi's Route function. Many handlers contain sub-handlers from their respective sub-packages.

Package api also contains some utility packages that are used across API endpoints. These include consistent error messages and middlewares used across the API.

Index

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 is the main API handler. This is basically the root entrypoint of the Karman API. All other API endpoints are created as sub-handlers of this controller.

func NewHandler

func NewHandler(logger *slog.Logger, hc HealthChecker, songRepo song.Repository, songSvc song.Service, mediaSvc media.Service, mediaStore media.Store, uploadRepo upload.Repository, uploadStore upload.Store, debug bool) *Handler

NewHandler creates a new Handler instance using the specified dependencies. The injected dependencies are passed along to the sub-handlers. debug indicates whether additional debugging features should be enabled.

func (*Handler) Healthz

func (h *Handler) Healthz(w http.ResponseWriter, r *http.Request)

Healthz implements the /healthz endpoint.

func (*Handler) MethodNotAllowed

func (*Handler) MethodNotAllowed(w http.ResponseWriter, r *http.Request)

MethodNotAllowed is an HTTP endpoint that renders a generic 405 Method Not Allowed error. This endpoint is the default 405 endpoint for the Handler and its sub-handlers.

func (*Handler) NotAcceptable

func (*Handler) NotAcceptable(w http.ResponseWriter, r *http.Request)

NotAcceptable is an HTTP endpoint that renders a generic 406 Not Acceptable error. This endpoint is the default 406 endpoint fo the Handler and its sub-handlers.

func (*Handler) NotFound

func (*Handler) NotFound(w http.ResponseWriter, r *http.Request)

NotFound is an HTTP endpoint that renders a generic 404 Not Found error. This endpoint is the default 404 endpoint for the Handler and its sub-handlers.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP processes HTTP requests for h.

type HealthCheckFunc

type HealthCheckFunc func(ctx context.Context) bool

HealthCheckFunc is a convenience wrapper around HealthChecker.

func (HealthCheckFunc) HealthCheck

func (f HealthCheckFunc) HealthCheck(ctx context.Context) bool

HealthCheck invokes f.

type HealthChecker

type HealthChecker interface {
	// HealthCheck performs a health check and returns its result.
	// A result of true indicates that the system is healthy.
	HealthCheck(ctx context.Context) bool
}

HealthChecker is an interface that can provide information about the system health.

Directories

Path Synopsis
Package apierror provides two things: an implementation of [RFC 9457] and convenience functions that generate the errors returned by the Karman API.
Package apierror provides two things: an implementation of [RFC 9457] and convenience functions that generate the errors returned by the Karman API.
Package middleware provides some of the middlewares used in the Karman API.
Package middleware provides some of the middlewares used in the Karman API.
Package schema contains HTTP request and response schemas used throughout the Karman API.
Package schema contains HTTP request and response schemas used throughout the Karman API.
v1
dav

Jump to

Keyboard shortcuts

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