httpclient

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 8 Imported by: 5 modules, 5 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.

README

component-httpclient - Settings component for generate HTTP clients

Overview

This is a settings that enables constructing a smart HTTP client from a transportd configuration. The purpose of this component is to enable Go projects using transportd as a proxy to statically link the proxy behavior with the Go application. We use this, for example, to run our code in serverless environments where additional functionality cannot be run as a separate process.

Quick Start

package main

import (
    "context"
    "net/http"

    httpclient "github.com/asecurityteam/component-httpclient"
    "github.com/asecurityteam/settings"
)

func main() {
    ctx := context.Background()
    envSource := settings.NewEnvSource(os.Environ())

    tr := httpclient.New(ctx, envSource)

    c := &http.Client{
        Transport: tr,
    }
}

Status

This project is in incubation which means we are not yet operating this tool in production and the interfaces are subject to change.

Contributing

Building And Testing

We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:

  • make dep

    Install the project dependencies into a vendor directory

  • make lint

    Run our static analysis suite

  • make test

    Run unit tests and generate a coverage artifact

  • make integration

    Run integration tests and generate a coverage artifact

  • make coverage

    Report the combined coverage for unit and integration tests

License

This project is licensed under Apache 2.0. See LICENSE.txt for details.

Contributing Agreement

Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.

Documentation

Index

Constants

View Source
const (
	// TypeDefault is used to select the default Go HTTP client.
	TypeDefault = "DEFAULT"
	// TypeSmart is used to select the transportd HTTP client.
	TypeSmart = "SMART"
)

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, source settings.Source, c *Component) (http.RoundTripper, error)

Load is a convenience method for binding the source to the component.

func New

func New(ctx context.Context, source settings.Source) (http.RoundTripper, error)

New is the top-level entry point for creating a new HTTP client. The default set of plugins will be installed for the smart client. Use the LoadHTTP() method if a custom set of plugins are required.

Types

type Component

type Component struct {
	Default *DefaultComponent
	Smart   *SmartComponent
}

Component is the top level HTTP client component.

func NewComponent

func NewComponent() *Component

NewComponent populates an HTTPComponent with defaults.

func (*Component) New

func (c *Component) New(ctx context.Context, conf *Config) (http.RoundTripper, error)

New constructs a client from the given configuration.

func (*Component) Settings

func (c *Component) Settings() *Config

Settings returns the default configuration.

type Config

type Config struct {
	Type    string `description:"The type of HTTP client. Choices are SMART and DEFAULT."`
	Default *DefaultConfig
	Smart   *SmartConfig
}

Config wraps all HTTP related settings.

func (*Config) Name

func (*Config) Name() string

Name of the config.

type DefaultComponent

type DefaultComponent struct{}

DefaultComponent is a component for creating the default Go HTTP client.

func (*DefaultComponent) New

New constructs a client from the given configuration

func (*DefaultComponent) Settings

func (*DefaultComponent) Settings() *DefaultConfig

Settings returns the default configuration.

type DefaultConfig

type DefaultConfig struct {
	ContentType string
}

DefaultConfig contains all settings for the default Go HTTP client.

type RoundTripper

type RoundTripper = http.RoundTripper

RoundTripper is the interface that handles all HTTP operations. It is almost exclusively used with an http.Client wrapped around it. This is included here for documentation purposes only.

type SmartComponent

type SmartComponent struct {
	Plugins []transportd.NewComponent
}

SmartComponent is a component for creating a transportd HTTP client.

func (*SmartComponent) New

New constructs a client from the given configuration.

func (*SmartComponent) Settings

func (*SmartComponent) Settings() *SmartConfig

Settings returns the default configuration.

type SmartConfig

type SmartConfig struct {
	OpenAPI string `description:"The full OpenAPI specification with transportd extensions."`
}

SmartConfig contains all settings for the transportd HTTP client.

func (*SmartConfig) Name

func (*SmartConfig) Name() string

Name of the configuration tree.

Jump to

Keyboard shortcuts

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