api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OkHandler added in v0.3.2

func OkHandler(ctx context.Context) http.Handler

OkHandler returns a handler that will serve status ok

Types

type API added in v0.3.1

type API interface {
	Run(ctx context.Context) error
	Shutdown(ctx context.Context) error
	RegisterRoutes(ctx context.Context, routes ...Route) error
}

func New added in v0.3.1

func New(cfg Config) API

New creates a new api

type APIMock added in v0.3.1

type APIMock struct {
	// RegisterRoutesFunc mocks the RegisterRoutes method.
	RegisterRoutesFunc func(ctx context.Context, routes ...Route) error

	// RunFunc mocks the Run method.
	RunFunc func(ctx context.Context) error

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

APIMock is a mock implementation of API.

func TestSomethingThatUsesAPI(t *testing.T) {

	// make and configure a mocked API
	mockedAPI := &APIMock{
		RegisterRoutesFunc: func(ctx context.Context, routes ...Route) error {
			panic("mock out the RegisterRoutes method")
		},
		RunFunc: func(ctx context.Context) error {
			panic("mock out the Run method")
		},
		ShutdownFunc: func(ctx context.Context) error {
			panic("mock out the Shutdown method")
		},
	}

	// use mockedAPI in code that requires API
	// and then make assertions.

}

func (*APIMock) RegisterRoutes added in v0.3.1

func (mock *APIMock) RegisterRoutes(ctx context.Context, routes ...Route) error

RegisterRoutes calls RegisterRoutesFunc.

func (*APIMock) RegisterRoutesCalls added in v0.3.1

func (mock *APIMock) RegisterRoutesCalls() []struct {
	Ctx    context.Context
	Routes []Route
}

RegisterRoutesCalls gets all the calls that were made to RegisterRoutes. Check the length with:

len(mockedAPI.RegisterRoutesCalls())

func (*APIMock) Run added in v0.3.1

func (mock *APIMock) Run(ctx context.Context) error

Run calls RunFunc.

func (*APIMock) RunCalls added in v0.3.1

func (mock *APIMock) RunCalls() []struct {
	Ctx context.Context
}

RunCalls gets all the calls that were made to Run. Check the length with:

len(mockedAPI.RunCalls())

func (*APIMock) Shutdown added in v0.3.1

func (mock *APIMock) Shutdown(ctx context.Context) error

Shutdown calls ShutdownFunc.

func (*APIMock) ShutdownCalls added in v0.3.1

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

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

len(mockedAPI.ShutdownCalls())

type Config added in v0.3.1

type Config struct {
	ListeningAddress string    `yaml:"address" mapstructure:"address"`
	Tls              TLSConfig `yaml:"tls" mapstructure:"tls"`
}

Config is the configuration for the data API

func (*Config) Validate added in v0.4.0

func (a *Config) Validate() error

type ErrCreateOpenapiSchema added in v0.3.1

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

func (ErrCreateOpenapiSchema) Error added in v0.3.1

func (e ErrCreateOpenapiSchema) Error() string

type Route added in v0.3.1

type Route struct {
	Path    string
	Method  string
	Handler http.HandlerFunc
}

type TLSConfig added in v0.4.0

type TLSConfig struct {
	Enabled  bool   `yaml:"enabled" mapstructure:"enabled"`
	CertPath string `yaml:"certPath" mapstructure:"certPath"`
	KeyPath  string `yaml:"keyPath" mapstructure:"keyPath"`
}

Jump to

Keyboard shortcuts

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