token

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: 4 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 (
	// TokenFieldName токен
	TokenFieldName = "client.http.auth.token.token"

	// HeaderNameFieldName имя заголовка
	HeaderNameFieldName = "client.http.auth.token.header"
)

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.Token, TokenFieldName, "", "")
			flagSet.StringVar(&config.HeaderName, HeaderNameFieldName, HeaderNameDefault, "")
		})
	}),
	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 'TokenAuth'")

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

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

View Source
var HeaderNameDefault = "X-Auth-Token"

HeaderNameDefault имя заголовка по умолчанию

Functions

func Middleware

func Middleware(config *Config) httpClient.MiddlewareFunc

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

Types

type Auth

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

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

func NewAuth

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

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

func (*Auth) RoundTrip

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

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

type Config

type Config struct {
	HeaderName string
	Token      string
}

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

func Configuration

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

Configuration загружает конфигурацию из Configurator.

func NewConfig

func NewConfig() *Config

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

Jump to

Keyboard shortcuts

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