base

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 5 Imported by: 0 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 (
	// CredFieldName — имя поля для учетных данных (логин:пароль).
	CredFieldName = "client.http.auth.base.cred"
)

Variables

View Source
var Component = compogo.Component{
	Dependencies: compogo.Components{
		&httpClient.Component,
	},
	Init: compogo.StepFunc(func(container compogo.Container) error {
		return container.Provides(
			NewConfig,
		)
	}),
	BindFlags: compogo.BindFlags(func(flagSet flag.FlagSet, container compogo.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.StringVar(&config.base, CredFieldName, "", "login:password pairs for basic authorization in http request")
		})
	}),
	Configuration: compogo.StepFunc(func(container compogo.Container) error {
		return container.Invoke(Configuration)
	}),
	PreExecute: compogo.StepFunc(func(container compogo.Container) error {
		return container.Provides(func(doer httpClient.Doer, logger compogo.Logger, config *Config) {
			logger.GetLogger("http").GetLogger("client").Info("usage 'BaseAuth'")

			doer.Use(Middleware(config))
		})
	}),
}

Component — компонент Basic Auth для HTTP-клиента.

Functions

func Middleware

func Middleware(config *Config) httpClient.MiddlewareFunc

Middleware возвращает MiddlewareFunc для Basic Auth.

Types

type Auth

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

Auth — RoundTripper для Basic Authentication. Добавляет заголовок Authorization: Basic при каждом запросе.

func NewAuth

func NewAuth(config *Config, transport http.RoundTripper) *Auth

NewAuth создаёт новый Basic Auth RoundTripper.

func (*Auth) RoundTrip

func (a *Auth) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip реализует интерфейс http.RoundTripper. Добавляет Basic Auth к запросу.

type Config

type Config struct {
	Base *Cred
	// contains filtered or unexported fields
}

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

func Configuration

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

Configuration загружает конфигурацию из Configurator. Парсит строку "логин:пароль" в структуру Cred.

func NewConfig

func NewConfig() *Config

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

type Cred

type Cred struct {
	Username string
	Password string
}

Cred содержит учетные данные для Basic Authentication.

Jump to

Keyboard shortcuts

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