api

package
v0.0.0-...-b06ef97 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2018 License: MIT Imports: 19 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 Controller

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

Controller is the api rest controller

func NewController

func NewController(repo Repository, notifier notifier.Notifier) *Controller

NewController creates a new instance of Controller

func (*Controller) DeleteBy

func (c *Controller) DeleteBy() http.HandlerFunc

DeleteBy is the delete handler

func (*Controller) Get

func (c *Controller) Get() http.HandlerFunc

Get is the find all handler

func (*Controller) GetBy

func (c *Controller) GetBy() http.HandlerFunc

GetBy is the find by handler

func (*Controller) Post

func (c *Controller) Post() http.HandlerFunc

Post is the create handler

func (*Controller) PutBy

func (c *Controller) PutBy() http.HandlerFunc

PutBy is the update handler

type Definition

type Definition struct {
	Name        string            `bson:"name" json:"name" valid:"required~name is required"`
	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
	sync.RWMutex
}

FileSystemRepository represents a mongodb repository

func NewFileSystemRepository

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

NewFileSystemRepository creates a mongo country repo

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) Add

func (r *InMemoryRepository) Add(definition *Definition) error

Add adds an api definition to the repository

func (*InMemoryRepository) Exists

func (r *InMemoryRepository) Exists(def *Definition) (bool, error)

Exists searches an existing Proxy definition by its listen_path

func (*InMemoryRepository) FindAll

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

FindAll fetches all the api definitions available

func (*InMemoryRepository) FindByListenPath

func (r *InMemoryRepository) FindByListenPath(path string) (*Definition, error)

FindByListenPath find an API definition by proxy listen path

func (*InMemoryRepository) FindByName

func (r *InMemoryRepository) FindByName(name string) (*Definition, error)

FindByName find an api definition by name

func (*InMemoryRepository) FindValidAPIHealthChecks

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

FindValidAPIHealthChecks retrieves all apis that has health check configured

func (*InMemoryRepository) Remove

func (r *InMemoryRepository) Remove(name string) error

Remove removes an api definition from the repository

type MongoRepository

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

MongoRepository represents a mongodb repository

func NewMongoAppRepository

func NewMongoAppRepository(session *mgo.Session) (*MongoRepository, error)

NewMongoAppRepository creates a mongo API definition repo

func (*MongoRepository) Add

func (r *MongoRepository) Add(definition *Definition) error

Add adds an API definition to the repository

func (*MongoRepository) Exists

func (r *MongoRepository) Exists(def *Definition) (bool, error)

Exists searches an existing API definition by its listen_path

func (*MongoRepository) FindAll

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

FindAll fetches all the API definitions available

func (*MongoRepository) FindByListenPath

func (r *MongoRepository) FindByListenPath(path string) (*Definition, error)

FindByListenPath find an API definition by proxy listen path

func (*MongoRepository) FindByName

func (r *MongoRepository) FindByName(name string) (*Definition, error)

FindByName find an API definition by name

func (*MongoRepository) FindValidAPIHealthChecks

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

FindValidAPIHealthChecks retrieves all active apis that has health check configured

func (*MongoRepository) Remove

func (r *MongoRepository) Remove(name string) error

Remove removes an API definition from the repository

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 {
	FindAll() ([]*Definition, error)
	FindByName(name string) (*Definition, error)
	FindByListenPath(path string) (*Definition, error)
	Exists(def *Definition) (bool, error)
	Add(app *Definition) error
	Remove(name string) error
	FindValidAPIHealthChecks() ([]*Definition, error)
}

Repository defines the behavior of a proxy specs repository

func BuildRepository

func BuildRepository(dsn string, session *mgo.Session) (Repository, error)

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

type Spec

type Spec struct {
	*Definition
}

Spec Holds an api definition and basic options

Jump to

Keyboard shortcuts

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