localproxy

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllocateEventType represents an event received by the server when it is allocated.
	AllocateEventType = EventType("AllocateEventType")

	// DeallocateEventType represents an event received by the server when it is deallocated.
	DeallocateEventType = EventType("DeallocateEventType")
)

Variables

This section is empty.

Functions

func NewUnexpectedResponseWithBody added in v0.3.0

func NewUnexpectedResponseWithBody(requestID string, statusCode int, responseBody []byte) *model.UnexpectedResponseError

NewUnexpectedResponseWithBody creates a new UnexpectedResponseError from a response body.

func NewUnexpectedResponseWithError added in v0.3.0

func NewUnexpectedResponseWithError(requestID string, statusCode int, err error) *model.UnexpectedResponseError

NewUnexpectedResponseWithError creates a new UnexpectedResponseError from an error.

Types

type AllocateEvent

type AllocateEvent struct {
	*BaseEvent
	AllocationID string `json:"AllocationID"`
}

AllocateEvent represents the data received on an allocation event.

type BaseEvent

type BaseEvent struct {
	Typ      EventType `json:"EventType"`
	EventID  string    `json:"EventID"`
	ServerID int64     `json:"ServerID"`
}

BaseEvent represents the base structure of all events received by the subscriber.

func (*BaseEvent) Type

func (b *BaseEvent) Type() EventType

Type returns the type of the event.

type Client

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

Client represents a client to the local proxy.

func New

func New(host string, serverID int64, chanError chan<- error) (*Client, error)

New constructs a new instance of the local proxy client.

func (*Client) HoldSelf added in v0.4.0

func (c *Client) HoldSelf(ctx context.Context, args *model.HoldRequest) (*model.HoldStatus, error)

HoldSelf triggers the local proxy endpoint to hold this server instance.

func (*Client) HoldStatus added in v0.4.0

func (c *Client) HoldStatus(ctx context.Context) (*model.HoldStatus, error)

HoldStatus triggers the local proxy endpoint to get the status of the hold for this server instance.

func (*Client) OnPublish

func (c *Client) OnPublish(_ *centrifuge.Subscription, e centrifuge.PublishEvent)

OnPublish implements centrifuge.PublishHandler and is triggered when a message is published to this subscriber.

func (*Client) OnSubscribeError

func (c *Client) OnSubscribeError(_ *centrifuge.Subscription, _ centrifuge.SubscribeErrorEvent)

OnSubscribeError implements centrifuge.SubscribeErrorHandler and is triggered when an error is encountered with this subscriber.

func (*Client) OnSubscribeSuccess

func (c *Client) OnSubscribeSuccess(_ *centrifuge.Subscription, _ centrifuge.SubscribeSuccessEvent)

OnSubscribeSuccess implements centrifuge.SubscribeSuccessHandler and is triggered when the client has successfully subscribed to the broker.

func (*Client) PatchAllocation added in v0.5.0

func (c *Client) PatchAllocation(ctx context.Context, allocationID string, args *model.PatchAllocationRequest) error

PatchAllocation triggers the local proxy endpoint to patch this server allocation.

func (*Client) RegisterCallback

func (c *Client) RegisterCallback(ev EventType, cb func(Event))

RegisterCallback registers a callback function for the specified EventType.

func (*Client) ReleaseSelf added in v0.4.0

func (c *Client) ReleaseSelf(ctx context.Context) error

ReleaseSelf triggers the local proxy endpoint to release the hold on this server instance.

func (*Client) ReserveSelf added in v0.3.0

func (c *Client) ReserveSelf(ctx context.Context, args *model.ReserveRequest) (*model.ReserveResponse, error)

ReserveSelf triggers the local proxy endpoint to reserve this server instance. Only applicable for reservation-based fleets.

func (*Client) Start

func (c *Client) Start() error

Start subscribes to the centrifuge broker and connects to it. Start() blocks until the client has subscribed successfully.

func (*Client) Stop

func (c *Client) Stop() error

Stop stops the client.

func (*Client) UnreserveSelf added in v0.3.0

func (c *Client) UnreserveSelf(ctx context.Context) error

UnreserveSelf triggers the local proxy endpoint to unreserve this server instance. Only applicable for reservation-based fleets.

type DeallocateEvent

type DeallocateEvent struct {
	*BaseEvent
	AllocationID string `json:"AllocationID"`
}

DeallocateEvent represents the data received on a deallocation event.

type Event

type Event interface {
	Type() EventType
}

Event represents the interface for any event received by the subscriber.

type EventType

type EventType string

EventType is a type alias for an event received by the subscriber.

Jump to

Keyboard shortcuts

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