web

package
v2.0.0-alpha.3+incompa... Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	ListenAndServe() error
	Addr() string
	ListenPath(path string, method string, handler http.HandlerFunc) error
	CheckHealth() error
	Shutdown(ctx context.Context)
}

func NewHTTPConnection

func NewHTTPConnection(bindAddr string, port int, logger logger.Logger) Connection

NewHTTPConnection creates a new connection and bind to the given address and port

type ConnectionMock

type ConnectionMock struct {
	// AddrFunc mocks the Addr method.
	AddrFunc func() string

	// CheckHealthFunc mocks the CheckHealth method.
	CheckHealthFunc func() error

	// ListenAndServeFunc mocks the ListenAndServe method.
	ListenAndServeFunc func() error

	// ListenPathFunc mocks the ListenPath method.
	ListenPathFunc func(path string, method string, handler http.HandlerFunc) error

	// ShutdownFunc mocks the Shutdown method.
	ShutdownFunc func(ctx context.Context)
	// contains filtered or unexported fields
}

ConnectionMock is a mock implementation of Connection.

    func TestSomethingThatUsesConnection(t *testing.T) {

        // make and configure a mocked Connection
        mockedConnection := &ConnectionMock{
            AddrFunc: func() string {
	               panic("TODO: mock out the Addr method")
            },
            CheckHealthFunc: func() error {
	               panic("TODO: mock out the CheckHealth method")
            },
            ListenAndServeFunc: func() error {
	               panic("TODO: mock out the ListenAndServe method")
            },
            ListenPathFunc: func(path string, method string, handler http.HandlerFunc) error {
	               panic("TODO: mock out the ListenPath method")
            },
            ShutdownFunc: func(ctx context.Context)  {
	               panic("TODO: mock out the Shutdown method")
            },
        }

        // TODO: use mockedConnection in code that requires Connection
        //       and then make assertions.

    }

func (*ConnectionMock) Addr

func (mock *ConnectionMock) Addr() string

Addr calls AddrFunc.

func (*ConnectionMock) AddrCalls

func (mock *ConnectionMock) AddrCalls() []struct {
}

AddrCalls gets all the calls that were made to Addr. Check the length with:

len(mockedConnection.AddrCalls())

func (*ConnectionMock) CheckHealth

func (mock *ConnectionMock) CheckHealth() error

CheckHealth calls CheckHealthFunc.

func (*ConnectionMock) CheckHealthCalls

func (mock *ConnectionMock) CheckHealthCalls() []struct {
}

CheckHealthCalls gets all the calls that were made to CheckHealth. Check the length with:

len(mockedConnection.CheckHealthCalls())

func (*ConnectionMock) ListenAndServe

func (mock *ConnectionMock) ListenAndServe() error

ListenAndServe calls ListenAndServeFunc.

func (*ConnectionMock) ListenAndServeCalls

func (mock *ConnectionMock) ListenAndServeCalls() []struct {
}

ListenAndServeCalls gets all the calls that were made to ListenAndServe. Check the length with:

len(mockedConnection.ListenAndServeCalls())

func (*ConnectionMock) ListenPath

func (mock *ConnectionMock) ListenPath(path string, method string, handler http.HandlerFunc) error

ListenPath calls ListenPathFunc.

func (*ConnectionMock) ListenPathCalls

func (mock *ConnectionMock) ListenPathCalls() []struct {
	Path    string
	Method  string
	Handler http.HandlerFunc
}

ListenPathCalls gets all the calls that were made to ListenPath. Check the length with:

len(mockedConnection.ListenPathCalls())

func (*ConnectionMock) Shutdown

func (mock *ConnectionMock) Shutdown(ctx context.Context)

Shutdown calls ShutdownFunc.

func (*ConnectionMock) ShutdownCalls

func (mock *ConnectionMock) ShutdownCalls() []struct {
	Ctx context.Context
}

ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:

len(mockedConnection.ShutdownCalls())

type ConnectionPool

type ConnectionPool interface {
	GetConnection(bindAddr string, port int, log logger.Logger) (Connection, error)
}

ConnectionPool defines the interface for http ConnectionPools

type ConnectionPoolMock

type ConnectionPoolMock struct {
	// GetConnectionFunc mocks the GetConnection method.
	GetConnectionFunc func(bindAddr string, port int, log logger.Logger) (Connection, error)
	// contains filtered or unexported fields
}

ConnectionPoolMock is a mock implementation of ConnectionPool.

    func TestSomethingThatUsesConnectionPool(t *testing.T) {

        // make and configure a mocked ConnectionPool
        mockedConnectionPool := &ConnectionPoolMock{
            GetConnectionFunc: func(bindAddr string, port int, log logger.Logger) (Connection, error) {
	               panic("TODO: mock out the GetConnection method")
            },
        }

        // TODO: use mockedConnectionPool in code that requires ConnectionPool
        //       and then make assertions.

    }

func (*ConnectionPoolMock) GetConnection

func (mock *ConnectionPoolMock) GetConnection(bindAddr string, port int, log logger.Logger) (Connection, error)

GetConnection calls GetConnectionFunc.

func (*ConnectionPoolMock) GetConnectionCalls

func (mock *ConnectionPoolMock) GetConnectionCalls() []struct {
	BindAddr string
	Port     int
	Log      logger.Logger
}

GetConnectionCalls gets all the calls that were made to GetConnection. Check the length with:

len(mockedConnectionPool.GetConnectionCalls())

type HTTPConnection

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

HTTPConnection defines an HTTP Connection and is a wrapper for http.Server

func (*HTTPConnection) Addr

func (h *HTTPConnection) Addr() string

Addr returns the bound address for the connection

func (*HTTPConnection) CheckHealth

func (h *HTTPConnection) CheckHealth() error

CheckHealth checks the health of the connection and returns an error if unhealthy

func (*HTTPConnection) ListenAndServe

func (h *HTTPConnection) ListenAndServe() error

ListenAndServe calls the http.Server ListenAndServe method

func (*HTTPConnection) ListenPath

func (h *HTTPConnection) ListenPath(path string, method string, handler http.HandlerFunc) error

ListenPath registers a new http.HandlerFunc at the given path

func (*HTTPConnection) Shutdown

func (h *HTTPConnection) Shutdown(ctx context.Context)

Shutdown shuts down the connection

type HTTPConnectionPool

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

HTTPConnectionPool is a concrete implementation of ConnectionPool

func NewHTTPConnectionPool

func NewHTTPConnectionPool() *HTTPConnectionPool

func (*HTTPConnectionPool) GetConnection

func (h *HTTPConnectionPool) GetConnection(bindAddr string, port int, logger logger.Logger) (Connection, error)

GetConnection return a http server from the pool if one exists, or creates a new http server and starts listening. This method needs a complete update to take into account https

type HTTPProvider

type HTTPProvider struct {
	Protocol  string               `hcl:"protocol,optional"` // default to http
	Server    string               `hcl:"server"`
	Port      int                  `hcl:"port,optional"`   // default to 80
	Method    string               `hcl:"method,optional"` // default to POST
	Path      string               `hcl:"path,optional"`   // default to /
	TLS       *providers.TLS       `hcl:"tls_config,block"`
	AuthBasic *providers.AuthBasic `hcl:"auth_basic,block"`
	AuthMTLS  *providers.AuthMTLS  `hcl:"auth_mtls,block"`
	// contains filtered or unexported fields
}

func NewHTTPProvider

func NewHTTPProvider(
	name, direction string,
	cp ConnectionPool, l logger.Logger) *HTTPProvider

func (*HTTPProvider) Direction

func (h *HTTPProvider) Direction() string

func (*HTTPProvider) Listen

func (h *HTTPProvider) Listen() (<-chan *providers.Message, error)

func (*HTTPProvider) Name

func (sp *HTTPProvider) Name() string

func (*HTTPProvider) Publish

func (h *HTTPProvider) Publish(msg providers.Message) (providers.Message, error)

func (*HTTPProvider) Setup

func (h *HTTPProvider) Setup() error

func (*HTTPProvider) Stop

func (h *HTTPProvider) Stop() error

func (*HTTPProvider) Type

func (h *HTTPProvider) Type() string

Jump to

Keyboard shortcuts

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