{"modulePath":"github.com/Compogo/http_client","version":"v1.0.0-rc1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package http_client\n\n## Constants\n\n```go\nconst (\n\t// TimeoutFieldName таймаут запроса\n\tTimeoutFieldName = \"client.http.timeout\"\n\n\t// MaxIdleConnectionsFieldName общее количество простаивающих соединений\n\tMaxIdleConnectionsFieldName = \"client.http.maximum.idle.connections\"\n\n\t// MaxIdleConnectionsPerHostFieldName простаивающие соединения на хост\n\tMaxIdleConnectionsPerHostFieldName = \"client.http.maximum.idle.host\"\n\n\t// MaxConnectionsPerHostFieldName всего соединений на хост\n\tMaxConnectionsPerHostFieldName = \"client.http.maximum.connections\"\n\n\t// SecureVerifyFieldName проверка TLS сертификата\n\tSecureVerifyFieldName = \"client.http.secure_verify\"\n\n\t// ResolverDNSFieldName DNS-сервер для разрешения\n\tResolverDNSFieldName = \"client.http.resolver.dns\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\tTimeoutDefault                   = 30 * time.Second\n\tMaxIdleConnectionsDefault        = uint16(100)\n\tMaxIdleConnectionsPerHostDefault = uint16(10)\n\tMaxConnectionsPerHostDefault     = uint16(20)\n\tSecureVerifyDefault              = true\n)\n```\n\n```go\nvar Component = compogo.Component{\n\tName: \"http.client\",\n\tInit: compogo.StepFunc(func(container compogo.Container) error {\n\t\treturn container.Provides(\n\t\t\tNewConfig,\n\t\t\tNewDecorator,\n\t\t\tfunc(decorator *Decorator) Doer { return decorator },\n\t\t)\n\t}),\n\tBindFlags: compogo.BindFlags(func(flagSet flag.FlagSet, container compogo.Container) error {\n\t\treturn container.Invoke(func(config *Config) {\n\t\t\tflagSet.DurationVar(\u0026config.Timeout, TimeoutFieldName, TimeoutDefault, \"request timeout\")\n\t\t\tflagSet.Uint16Var(\u0026config.MaxIdleConnections, MaxIdleConnectionsFieldName, MaxIdleConnectionsDefault, \"maximum total number of open connections\")\n\t\t\tflagSet.Uint16Var(\u0026config.MaxIdleConnectionsPerHost, MaxIdleConnectionsPerHostFieldName, MaxIdleConnectionsPerHostDefault, \"maximum number of open connections per host\")\n\t\t\tflagSet.Uint16Var(\u0026config.MaxConnectionsPerHost, MaxConnectionsPerHostFieldName, MaxConnectionsPerHostDefault, \"maximum number of connections per host\")\n\t\t\tflagSet.BoolVar(\u0026config.SecureVerify, SecureVerifyFieldName, SecureVerifyDefault, \"if true, check the TLS certificate\")\n\t\t\tflagSet.StringVar(\u0026config.DNS, ResolverDNSFieldName, \"\", \"If specified, attempts to resolve domain names through the specified DNS server.\")\n\t\t})\n\t}),\n\tConfiguration: compogo.StepFunc(func(container compogo.Container) error {\n\t\treturn container.Invoke(Configuration)\n\t}),\n\tPreExecute: compogo.StepFunc(func(container compogo.Container) error {\n\t\treturn container.Invoke(func(config *Config, logger compogo.Logger) {\n\t\t\tlogger = logger.GetLogger(\"http\").GetLogger(\"client\")\n\n\t\t\tlogger.Infof(\"timeout - %s\", config.Timeout)\n\t\t\tlogger.Infof(\"maxIdleConnections - %d\", config.MaxIdleConnections)\n\t\t\tlogger.Infof(\"maxIdleConnectionsPerHost - %d\", config.MaxIdleConnectionsPerHost)\n\t\t\tlogger.Infof(\"maxConnectionsPerHost - %d\", config.MaxConnectionsPerHost)\n\t\t\tlogger.Infof(\"tls secure verify - %s\", strconv.FormatBool(config.SecureVerify))\n\n\t\t\tif config.DNS != \"\" {\n\t\t\t\tlogger.Infof(\"dns - %s\", config.DNS)\n\t\t\t}\n\t\t})\n\t}),\n}\n```\nComponent — компонент HTTP-клиента для Compogo. Регистрирует конфигурацию и клиент в DI-контейнере.\n\n## Types\n\n```go\ntype Config struct {\n\tTimeout                   time.Duration\n\tMaxIdleConnections        uint16\n\tMaxIdleConnectionsPerHost uint16\n\tMaxConnectionsPerHost     uint16\n\tSecureVerify              bool\n\tDNS                       string\n}\n```\nConfig содержит конфигурацию HTTP-клиента.\n\n```go\nfunc Configuration(config *Config, configurator compogo.Configurator) *Config\n```\nConfiguration загружает конфигурацию из Configurator. Если значения не заданы, устанавливаются значения по умолчанию.\n\n```go\nfunc NewConfig() *Config\n```\nNewConfig создаёт новую конфигурацию.\n\n```go\ntype Decorator struct {\n\t*http.Client\n}\n```\nDecorator — обёртка над http.Client с поддержкой middleware. Позволяет добавлять middleware через Use().\n\n```go\nfunc NewDecorator(config *Config) *Decorator\n```\nNewDecorator создаёт новый HTTP-клиент с конфигурацией. Настраивает:\n\n  - Таймауты\n  - Пул соединений (MaxIdleConns, MaxIdleConnsPerHost, MaxConnsPerHost)\n  - TLS (возможность отключить проверку сертификатов)\n  - Кастомный DNS-резолвер\n\n```go\nfunc (d *Decorator) Use(middlewares ...Middleware)\n```\nUse добавляет middleware в клиент. Middleware оборачивают Transport в цепочку обработки.\n\n```go\ntype Doer interface {\n\tDo(request *http.Request) (*http.Response, error)\n\tUse(middlewares ...Middleware)\n}\n```\nDoer определяет интерфейс для выполнения HTTP-запросов. Расширяет стандартный http.Client методом Use для добавления middleware.\n\n```go\ntype Middleware interface {\n\tMiddleware(next http.RoundTripper) http.RoundTripper\n}\n```\nMiddleware — интерфейс для обёртки http.RoundTripper. Позволяет добавлять логирование, аутентификацию, метрики и т.д.\n\n```go\ntype MiddlewareFunc func(next http.RoundTripper) http.RoundTripper\n```\nMiddlewareFunc — функциональный адаптер для Middleware.\n\n```go\nfunc (m MiddlewareFunc) Middleware(next http.RoundTripper) http.RoundTripper\n```\nMiddleware реализует интерфейс Middleware.\n\n","path":"github.com/Compogo/http_client","name":"http_client","synopsis":"","isRedistributable":true}
