httpconfig

package module
v0.0.0-...-a5d8f17 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: GPL-3.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

This module handles basic configuration of HTTP server. It provides a function for reading environment variables and can set up a logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvGet

func EnvGet[T any](name string, def T, parse func(string) (T, error)) (T, error)

A function used for reading environment variables. It accepts a variable name, a default value, and a parsing function. This parsing function accepts a string (the raw representation of the environment variable) and returns a parsed value and an error.

func LogMiddleware

func LogMiddleware(next http.Handler) http.Handler

This middleware logs http request data at debug level.

Types

type CfgLog

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

A configuration struct for the logger, populated from environmental variables.

func (*CfgLog) Config

func (cfg *CfgLog) Config() error

This method configures logging by reading values from the following environmental variables: - LOG_LEVEL: Minimum log level for emitted messages. Can be any value of slog.Level. - LOG_SOURCE - boolean value - defines if log should contain source code position of the log statement.

type CfgServer

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

A configuration struct for the HTTP server, populated from environmental variables.

func (*CfgServer) Config

func (cfg *CfgServer) Config() error

This method configures HTTP server by reading values from the following environmental variables: - ADDRESS: TCP address for the server to listen on. Defaults to 0.0.0.0 - PORT - Specifies TCP port for the server to listen on. Defaults to 8080

func (*CfgServer) GetServer

func (cfg *CfgServer) GetServer(mux *http.ServeMux) *http.Server

This method returns *http.Server based on provided mux and configuration parsed with Config method.

Jump to

Keyboard shortcuts

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