api

package
v2.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackendsIndex = func(backends []*domain.Backend, cluster ClusterManager) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		backendsJSON, err := json.Marshal(Backends(backends).AsV0JSON(cluster))

		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		_, err = w.Write(backendsJSON)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	})
}
View Source
var Cluster = func(cluster ClusterManager, logger lager.Logger) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		switch req.Method {
		case "GET":
			writeClusterResponse(w, cluster)
			return
		case "PATCH":
			handleUpdate(w, req, cluster, logger)
			writeClusterResponse(w, cluster)
			return
		default:
			http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
		}
	})
}

Functions

func NewHandler

func NewHandler(
	cluster ClusterManager,
	backends []*domain.Backend,
	logger lager.Logger,
	apiConfig config.API,
	staticDir string,
) http.Handler

Types

type BackendJSON

type BackendJSON struct {
	Host string `json:"host"`
	Port uint   `json:"port"`
	Name string `json:"name"`
}

type Backends

type Backends []*domain.Backend

func (Backends) AsV0JSON

func (bs Backends) AsV0JSON(cluster ClusterManager) (json []V0BackendResponse)

type ClusterAPI

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

func NewClusterAPI

func NewClusterAPI(
	trafficEnabledChan chan<- bool,
	activeBackendChan <-chan *domain.Backend,
	logger lager.Logger) *ClusterAPI

func (*ClusterAPI) AsJSON

func (c *ClusterAPI) AsJSON() ClusterJSON

func (*ClusterAPI) DisableTraffic

func (c *ClusterAPI) DisableTraffic(message string)

func (*ClusterAPI) EnableTraffic

func (c *ClusterAPI) EnableTraffic(message string)

func (*ClusterAPI) ListenForActiveBackend

func (c *ClusterAPI) ListenForActiveBackend()

type ClusterJSON

type ClusterJSON struct {
	ActiveBackend  *BackendJSON `json:"activeBackend"`
	TrafficEnabled bool         `json:"trafficEnabled"`
	Message        string       `json:"message"`
	LastUpdated    time.Time    `json:"lastUpdated"`
}

type ClusterManager

type ClusterManager interface {
	AsJSON() ClusterJSON
	EnableTraffic(string)
	DisableTraffic(string)
}

type V0BackendResponse

type V0BackendResponse struct {
	Host                string `json:"host"`
	Port                uint   `json:"port"`
	Healthy             bool   `json:"healthy"`
	Name                string `json:"name"`
	CurrentSessionCount uint   `json:"currentSessionCount"`
	Active              bool   `json:"active"`         // For Backwards Compatibility
	TrafficEnabled      bool   `json:"trafficEnabled"` // For Backwards Compatibility
}

Directories

Path Synopsis
This file was generated by counterfeiter
This file was generated by counterfeiter
fakes
This file was generated by counterfeiter
This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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