api

package
v0.0.0-...-a8f6685 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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

		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 ClusterEndpoint = func(clusterManager ClusterManager, logger lager.Logger) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		switch req.Method {
		case "GET":
			writeClusterResponse(w, clusterManager)
			return
		case "PATCH":
			handleUpdate(w, req, clusterManager, logger)
			writeClusterResponse(w, clusterManager)
			return
		default:
			http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
		}
	})
}

Functions

func NewHandler

func NewHandler(
	clusterManager 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 {
	ActiveBackendChan chan *domain.Backend
	// contains filtered or unexported fields
}

func NewClusterAPI

func NewClusterAPI(
	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()

func (*ClusterAPI) RegisterTrafficEnabledChan

func (c *ClusterAPI) RegisterTrafficEnabledChan(chanToRegister chan bool)

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
Code generated by counterfeiter.
Code 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