ejhttp

module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause

README

ElJef HTTP

ElJef HTTP is a Golang package for quickly setting up an HTTP service in a new project. This HTTP server does not target performance. Instead, it targets ease of implementation for small projects.

This package sets up a server that can take input as anything, but only returns data as JSON. This is perfect for writing bots with an admin interface, small web services, or glue services.

Concepts

Distributor

A distributor is the core HTTP endpoint handler. It provides the ServeHTTP method used for talking to an end point.

When ServeHTTP is called, the distributor automatically resolves the remote callers address, starting with reverse proxy headers X-Real-IP and X-Forwarded-For and then falls back to the HTTP Server provided Remote-Addr.

Logger

The Distributor then creates a new child logger with its own ID, holding its parents ID as well. This logger can be passed through all execution paths in a service, allowing for auditing and tracing.

Context

The Distributor creates a new context for each incoming request. The Context is passed down through all middleware for the Distributor, and the final end point handler. Data to be passed between middlewares and the final handler can store and retrieve data in the context.

Middlewares

Registered middlewares are called in order, having the context passed to them. Middlewares return a bool signaling if they executed correctly.

Handler

The final handler processes the request and writes and return data to the context. The Distributor will handle responding to the client based on the return code.

TODO

Expand documentation

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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