api

package
v0.0.0-...-98b9f36 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package api holds the models for the API Definition. On this package you can also find the default errors, handlers, loaders and repositories.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAPIDefinitionNotFound is used when the api was not found in the datastore
	ErrAPIDefinitionNotFound = errors.New(http.StatusNotFound, "api definition not found")

	// ErrAPINameExists is used when the API name is already registered on the datastore
	ErrAPINameExists = errors.New(http.StatusConflict, "api name is already registered")

	// ErrAPIListenPathExists is used when the API listen path is already registered on the datastore
	ErrAPIListenPathExists = errors.New(http.StatusConflict, "api listen path is already registered")

	// ErrDBContextNotSet is used when the database request context is not set
	ErrDBContextNotSet = errors.New(http.StatusInternalServerError, "DB context was not set for this request")
)

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Definitions []*Definition
}

Configuration represents all the api definitions

func (*Configuration) EqualsTo

func (c *Configuration) EqualsTo(c1 *Configuration) bool

EqualsTo compares two configurations and determines if they are the same

type ConfigurationChanged

type ConfigurationChanged struct {
	Configurations *Configuration
}

ConfigurationChanged is the message that is sent when a database configuration has changed

type ConfigurationMessage

type ConfigurationMessage struct {
	Operation     ConfigurationOperation
	Configuration *Definition
}

ConfigurationMessage is used to notify listeners about something that happened with a configuration

type ConfigurationOperation

type ConfigurationOperation int

ConfigurationOperation is the available operations that a configuration can have

const (
	// RemovedOperation means a definition was removed
	RemovedOperation ConfigurationOperation = iota
	// UpdatedOperation means a definition was updated
	UpdatedOperation
	// AddedOperation means a definition was added
	AddedOperation
)

type Definition

type Definition struct {
	Name        string            `` /* 147-byte string literal not displayed */
	Active      bool              `bson:"active" json:"active"`
	Proxy       *proxy.Definition `bson:"proxy" json:"proxy" valid:"required"`
	Plugins     []Plugin          `bson:"plugins" json:"plugins"`
	HealthCheck HealthCheck       `bson:"health_check" json:"health_check"`
}

Definition represents an API that you want to proxy

func NewDefinition

func NewDefinition() *Definition

NewDefinition creates a new API Definition with default values

func (*Definition) UnmarshalJSON

func (d *Definition) UnmarshalJSON(b []byte) error

UnmarshalJSON api.Definition JSON.Unmarshaller implementation

func (*Definition) Validate

func (d *Definition) Validate() (bool, error)

Validate validates proxy data

type FileSystemRepository

type FileSystemRepository struct {
	*InMemoryRepository
	// contains filtered or unexported fields
}

FileSystemRepository represents a mongodb repository

func NewFileSystemRepository

func NewFileSystemRepository(dir string) (*FileSystemRepository, error)

NewFileSystemRepository creates a mongo country repo

func (*FileSystemRepository) Close

func (r *FileSystemRepository) Close() error

Close terminates the session. It's a runtime error to use a session after it has been closed.

func (*FileSystemRepository) Watch

func (r *FileSystemRepository) Watch(ctx context.Context, cfgChan chan<- ConfigurationChanged)

Watch watches for changes on the database

type HealthCheck

type HealthCheck struct {
	URL     string `bson:"url" json:"url" valid:"url"`
	Timeout int    `bson:"timeout" json:"timeout"`
}

HealthCheck represents the health check configs

type InMemoryRepository

type InMemoryRepository struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

InMemoryRepository represents a in memory repository

func NewInMemoryRepository

func NewInMemoryRepository() *InMemoryRepository

NewInMemoryRepository creates a in memory repository

func (*InMemoryRepository) Close

func (r *InMemoryRepository) Close() error

Close terminates the session. It's a runtime error to use a session after it has been closed.

func (*InMemoryRepository) FindAll

func (r *InMemoryRepository) FindAll() ([]*Definition, error)

FindAll fetches all the api definitions available

func (*InMemoryRepository) Watch

func (r *InMemoryRepository) Watch(ctx context.Context, cfgChan chan<- ConfigurationChanged)

Watch watches for changes on the database

type Listener

type Listener interface {
	Listen(ctx context.Context, cfgChan <-chan ConfigurationMessage)
}

Listener defines how a provider should listen for changes on configurations

type MongoRepository

type MongoRepository struct {
	// TODO: we need to expose this so the plugins can use the same session. We should abstract the session and provide
	// the plugins with a simple interface to search, insert, update and remove data from whatever backend implementation
	Session *mgo.Session
	// contains filtered or unexported fields
}

MongoRepository represents a mongodb repository

func NewMongoAppRepository

func NewMongoAppRepository(dsn string, refreshTime time.Duration) (*MongoRepository, error)

NewMongoAppRepository creates a mongo API definition repo

func (*MongoRepository) Close

func (r *MongoRepository) Close() error

Close terminates the session. It's a runtime error to use a session after it has been closed.

func (*MongoRepository) FindAll

func (r *MongoRepository) FindAll() ([]*Definition, error)

FindAll fetches all the API definitions available

func (*MongoRepository) Listen

func (r *MongoRepository) Listen(ctx context.Context, cfgChan <-chan ConfigurationMessage)

Listen watches for changes on the configuration

func (*MongoRepository) Watch

func (r *MongoRepository) Watch(ctx context.Context, cfgChan chan<- ConfigurationChanged)

Watch watches for changes on the database

type Plugin

type Plugin struct {
	Name    string                 `bson:"name" json:"name"`
	Enabled bool                   `bson:"enabled" json:"enabled"`
	Config  map[string]interface{} `bson:"config" json:"config"`
}

Plugin represents the plugins for an API

type Repository

type Repository interface {
	io.Closer
	FindAll() ([]*Definition, error)
}

Repository defines the behavior of a proxy specs repository

func BuildRepository

func BuildRepository(dsn string, refreshTime time.Duration) (Repository, error)

BuildRepository creates a repository instance that will depend on your given DSN

type Watcher

type Watcher interface {
	Watch(ctx context.Context, cfgChan chan<- ConfigurationChanged)
}

Watcher defines how a provider should watch for changes on configurations

Jump to

Keyboard shortcuts

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