basic

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 9 Imported by: 1 module, 1 package

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

Index

Constants

View Source
const (
	// CredsFieldName is the command-line flag for inline credentials.
	// Format: "username1:password1,username2:password2"
	CredsFieldName = "server.http.auth.basic.creds"

	// FilePathFieldName is the command-line flag for credentials file.
	// File should contain one "username:password" per line.
	FilePathFieldName = "server.http.auth.basic.filepath"
)

Variables

View Source
var Component = &component.Component{
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewAuth,
		)
	}),
	Configuration: component.StepFunc(func(container container.Container) error {
		return container.Invoke(Configuration)
	}),
}

Component is a ready-to-use Compogo component that provides HTTP Basic Authentication middleware.

Usage:

compogo.WithComponents(
    http.Component,
    basic.Component,
)

Then in your router setup:

router.Use(basicAuth.Middleware)

Functions

This section is empty.

Types

type Auth

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

Auth implements HTTP Basic Authentication middleware. It validates incoming requests against configured credentials.

func NewAuth

func NewAuth(config *Config) *Auth

NewAuth creates a new Auth middleware instance with the given configuration.

func (*Auth) Middleware

func (auth *Auth) Middleware(next http.Handler) http.Handler

Middleware implements the http.Middleware interface. It checks for valid Basic Authentication credentials:

  • If no credentials or invalid credentials, returns 401 Unauthorized
  • If valid, passes the request to the next handler

type Config

type Config struct {
	FilePath string

	Creds mapper.Mapper[*Cred]
	// contains filtered or unexported fields
}

Config holds the basic authentication configuration. It can be populated from command-line flags, config files, or a credentials file.

func Configuration

func Configuration(config *Config, configurator configurator.Configurator) (*Config, error)

Configuration applies configuration values to the Config struct. It reads from configurator and optionally from a credentials file. Returns an error if file reading fails.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config instance with default values.

type Cred

type Cred struct {
	UserName string
	Password string
}

Cred represents a single username/password pair for basic authentication.

func (*Cred) String

func (c *Cred) String() string

String returns the username, implementing fmt.Stringer.

Jump to

Keyboard shortcuts

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