basic

package
v1.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT 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

Index

Constants

View Source
const (
	// CredsFieldName — имя поля для списка учетных данных (логин:пароль).
	CredsFieldName = "server.http.auth.basic.creds"

	// FilePathFieldName — имя поля для пути к файлу с учетными данными.
	FilePathFieldName = "server.http.auth.basic.filepath"
)

Variables

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

Component — компонент Basic Auth для Compogo. Регистрирует конфигурацию и middleware в DI-контейнере.

Functions

This section is empty.

Types

type Auth

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

Auth реализует HTTP Basic Authentication middleware. Проверяет учетные данные из заголовка Authorization.

func NewAuth

func NewAuth(config *Config) *Auth

NewAuth создаёт новый middleware для Basic Auth.

func (*Auth) Middleware

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

Middleware реализует интерфейс http_server.Middleware. Проверяет логин и пароль из заголовка Authorization. В случае неудачи возвращает 401 Unauthorized.

type Config

type Config struct {
	FilePath string

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

Config содержит конфигурацию Basic Auth.

func Configuration

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

Configuration загружает конфигурацию из Configurator. Поддерживает загрузку учетных данных из:

  • Параметра creds (срез строк "логин:пароль")
  • Файла (построчное чтение, каждая строка = "логин:пароль")

Пустые строки в файле игнорируются.

func NewConfig

func NewConfig() *Config

NewConfig создаёт новую конфигурацию.

type Cred

type Cred struct {
	UserName string
	Password string
}

Cred представляет учетные данные пользователя. Реализует fmt.Stringer для использования в mapper.

func (*Cred) String

func (c *Cred) String() string

String возвращает имя пользователя. Реализует интерфейс fmt.Stringer для mapper.

Jump to

Keyboard shortcuts

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