controllers

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ControllerInjector for binding controllers
	ControllerInjector = wire.NewSet(ConfigureAPI, NewRouter, NewStatusController, NewProducersController, NewProducerController, NewChannelController, NewChannelsController, NewConsumerController, NewConsumersController, NewBroadcastController, NewMessageController, NewMessagesController, NewDLQController, wire.Struct(new(Controllers), "StatusController", "ProducersController", "ProducerController", "ChannelController", "ConsumerController", "ConsumersController", "BroadcastController", "MessageController", "MessagesController", "DLQController", "ChannelsController"))
	// ErrUnsupportedMediaType is returned when client does not provide appropriate `Content-Type` header
	ErrUnsupportedMediaType = errors.New("Media type not supported")
	// ErrConditionalFailed is returned when update is missing `If-Unmodified-Since` header
	ErrConditionalFailed = errors.New("Update failed due to mismatch of `If-Unmodified-Since` header value")
	// ErrNotFound is returned when resource is not found
	ErrNotFound = errors.New("Request resource not found")
	// ErrBadRequest is returned when protocol for a PUT/POST/DELETE request is not met
	ErrBadRequest = errors.New("Bad Request: Update is missing `If-Unmodified-Since` header ")
	// ErrBadRequestForRequeue is returned when requeue form param does not match consumer token
	ErrBadRequestForRequeue = errors.New("`requeue` form param must match consumer token")
)
View Source
var NotifyOnInterrupt = func(stop *chan os.Signal) {
	signal.Notify(*stop, os.Interrupt, os.Kill, syscall.SIGTERM)
}

NotifyOnInterrupt registers channel to get notified when interrupt is captured

Functions

func ConfigureAPI

func ConfigureAPI(httpConfig config.HTTPConfig, iListener ServerLifecycleListener, apiRouter *httprouter.Router) *http.Server

ConfigureAPI configures API Server with interrupt handling

func NewRouter

func NewRouter(controllers *Controllers) *httprouter.Router

NewRouter returns a new instance of the router

Types

type AppData

type AppData struct {
	SeedData  *config.SeedData
	AppStatus data.AppStatus
}

AppData to deserialize in status endpoint

type BroadcastController

type BroadcastController struct {
	MessageRepository  storage.MessageRepository
	ChannelRepository  storage.ChannelRepository
	ProducerRepository storage.ProducerRepository
	Dispatcher         dispatcher.MessageDispatcher
}

BroadcastController receives new Message to broadcasted to a valid channel

func NewBroadcastController

func NewBroadcastController(channelRepo storage.ChannelRepository, msgRepo storage.MessageRepository, producerRepo storage.ProducerRepository, dispatcher dispatcher.MessageDispatcher) *BroadcastController

NewBroadcastController creates a new instance of the controller responsible for broadcasting a message

func (broadcastController *BroadcastController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*BroadcastController) GetPath

func (broadcastController *BroadcastController) GetPath() string

GetPath returns the endpoint's path

func (*BroadcastController) Post

func (broadcastController *BroadcastController) Post(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Post Receives message to be broadcasted to a channel

type ChannelController

type ChannelController struct {
	ChannelRepo       storage.ChannelRepository
	ConsumersEndpoint EndpointController
	MessagesEndpoint  EndpointController
	BroadcastEndpoint EndpointController
}

ChannelController is for /channel/:prodId

func NewChannelController

func NewChannelController(consumersController *ConsumersController, messagesController *MessagesController, broadcastController *BroadcastController, channelRepo storage.ChannelRepository) *ChannelController

NewChannelController initialize new channels controller

func (channelController *ChannelController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*ChannelController) Get

func (channelController *ChannelController) Get(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Get implements the /channel/:prodId GET endpoint

func (*ChannelController) GetPath

func (channelController *ChannelController) GetPath() string

GetPath returns the endpoint's path

func (*ChannelController) Put

func (channelController *ChannelController) Put(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Put implements the /channel/:prodId PUT endpoint

type ChannelModel

type ChannelModel struct {
	MsgStakeholder
	ConsumersURL string
	MessagesURL  string
	BroadcastURL string
}

ChannelModel represents the Channel data

type ChannelsController

type ChannelsController struct {
	ChannelRepo     storage.ChannelRepository
	ChannelEndpoint EndpointController
}

ChannelsController for handling `/channels` endpoint

func NewChannelsController

func NewChannelsController(channelRepo storage.ChannelRepository, channelController *ChannelController) *ChannelsController

NewChannelsController initialize new channels controller

func (channelsController *ChannelsController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*ChannelsController) Get

func (channelsController *ChannelsController) Get(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

Get implements the /channels endpoint

func (*ChannelsController) GetPath

func (channelsController *ChannelsController) GetPath() string

GetPath returns the endpoint's path

type ConsumerController

type ConsumerController struct {
	ConsumerRepo storage.ConsumerRepository
	ChannelRepo  storage.ChannelRepository
	DLQEndpoint  EndpointController
}

ConsumerController represents all endpoints related to a single consumer for a channel

func NewConsumerController

func NewConsumerController(channelRepo storage.ChannelRepository, consumerRepo storage.ConsumerRepository, DLQController *DLQController) *ConsumerController

NewConsumerController creates and returns a new instance of ConsumerController

func (*ConsumerController) Delete

func (controller *ConsumerController) Delete(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Delete implements the DELETE /channel/:channelId/consumer/:consumerId endpoint

func (controller *ConsumerController) FormatAsRelativeLink(params ...httprouter.Param) (result string)

FormatAsRelativeLink formats this controllers URL with the parameters provided. Both `consumerId` and `channelId` params must be sent else it will return the templated URL

func (*ConsumerController) Get

func (controller *ConsumerController) Get(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Get implements the GET /channel/:channelId/consumer/:consumerId endpoint

func (*ConsumerController) GetPath

func (controller *ConsumerController) GetPath() string

GetPath returns the endpoint's path

func (*ConsumerController) Put

func (controller *ConsumerController) Put(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Put implements the PUT /channel/:channelId/consumer/:consumerId endpoint

type ConsumerModel

type ConsumerModel struct {
	MsgStakeholder
	CallbackURL        string
	DeadLetterQueueURL string
}

ConsumerModel represents the data communicated to HTTP clients

type ConsumersController

type ConsumersController struct {
	ConsumerRepo     storage.ConsumerRepository
	ConsumerEndpoint EndpointController
}

ConsumersController represents all endpoints related to a consumers list for a channel

func NewConsumersController

func NewConsumersController(consumerEndpoint *ConsumerController, consumerRepo storage.ConsumerRepository) *ConsumersController

NewConsumersController creates and returns a new instance of ConsumersController

func (controller *ConsumersController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink formats this controllers URL with the parameters provided. Both `consumerId` and `channelId` params must be sent else it will return the templated URL

func (*ConsumersController) Get

func (controller *ConsumersController) Get(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Get implements the GET /channel/:channelId/consumers endpoint

func (*ConsumersController) GetPath

func (controller *ConsumersController) GetPath() string

GetPath returns the endpoint's path

type Controllers

type Controllers struct {
	StatusController    *StatusController
	ProducersController *ProducersController
	ProducerController  *ProducerController
	ChannelController   *ChannelController
	ChannelsController  *ChannelsController
	ConsumerController  *ConsumerController
	ConsumersController *ConsumersController
	BroadcastController *BroadcastController
	MessageController   *MessageController
	MessagesController  *MessagesController
	DLQController       *DLQController
}

Controllers represents factory object containing all the controllers

type DLQController

type DLQController struct {
	MessageController EndpointController
	DeliveryJobRepo   storage.DeliveryJobRepository
	ConsumerRepo      storage.ConsumerRepository
}

DLQController represents the GET and POST endpoint for reading dead and requeuing all dead messages for delivery.

func NewDLQController

func NewDLQController(msgController *MessageController, djRepo storage.DeliveryJobRepository, consumerRepo storage.ConsumerRepository) *DLQController

NewDLQController retrieves the controller for DLQ list and requeue endpoints

func (controller *DLQController) FormatAsRelativeLink(params ...httprouter.Param) (result string)

FormatAsRelativeLink formats this controllers URL with the parameters provided. Both `consumerId` and `channelId` params must be sent else it will return the templated URL

func (*DLQController) Get

func (controller *DLQController) Get(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Get Retrieves dead jobs for a specific consumer

func (*DLQController) GetPath

func (controller *DLQController) GetPath() string

GetPath returns the endpoint's path

func (*DLQController) Post

func (controller *DLQController) Post(w http.ResponseWriter, r *http.Request, params httprouter.Params)

Post Requeue dead jobs for another single delivery attempt

type DLQList

type DLQList struct {
	DeadJobs []*DeadDeliveryJobModel
	Pages    map[string]string
}

DLQList represents the list of jobs that are dead

type DeadDeliveryJobModel

type DeadDeliveryJobModel struct {
	DeliveryJobModel
	MessageURL string
}

DeadDeliveryJobModel is a DeliveryJobModel with reference to its message and to be used for DLQ

type Delete

type Delete interface {
	Delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Delete represents DELETE Method Call to a resource

type DeliveryJobModel

type DeliveryJobModel struct {
	ListenerEndpoint string
	ListenerName     string
	Status           string
	StatusChangedAt  time.Time
}

DeliveryJobModel represents a delivery job of a message

type EndpointController

type EndpointController interface {
	GetPath() string
	FormatAsRelativeLink(params ...httprouter.Param) string
}

EndpointController represents very basic functionality of an endpoint

type Get

type Get interface {
	Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Get represents GET Method Call to a resource

type ListResult

type ListResult struct {
	Result []string
	Pages  map[string]string
	Links  map[string]string
}

ListResult is the resource returned by /producers endpoint

type MessageController

type MessageController struct {
	MessageRepo     storage.MessageRepository
	DeliveryJobRepo storage.DeliveryJobRepository
}

MessageController represents the GET endpoint for a single message broadcasted to a channel

func NewMessageController

func NewMessageController(msgRepo storage.MessageRepository, djRepo storage.DeliveryJobRepository) *MessageController

NewMessageController initializes the message controller

func (messageController *MessageController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*MessageController) Get

func (messageController *MessageController) Get(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Get implements GET /channel/:channelId/message/:messageId

func (*MessageController) GetPath

func (messageController *MessageController) GetPath() string

GetPath returns the endpoint's path

type MessageModel

type MessageModel struct {
	Payload      string
	ContentType  string
	ProducedBy   string
	ReceivedAt   time.Time
	DispatchedAt time.Time
	Status       string
	Jobs         []*DeliveryJobModel
}

MessageModel represents a single message

type MessagesController

type MessagesController struct {
	MessageController EndpointController
	MessageRepo       storage.MessageRepository
}

MessagesController represents the GET endpoint for listing all messages broadcasted to a channel

func NewMessagesController

func NewMessagesController(msgController *MessageController, msgRepo storage.MessageRepository) *MessagesController

NewMessagesController initializes the controller for messages in a channel

func (messagesController *MessagesController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*MessagesController) Get

func (messagesController *MessagesController) Get(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Get implements GET /channel/:channelId/messages

func (*MessagesController) GetPath

func (messagesController *MessagesController) GetPath() string

GetPath returns the endpoint's path

type MsgStakeholder

type MsgStakeholder struct {
	ID        string
	Name      string
	Token     string
	ChangedAt time.Time
}

MsgStakeholder is the

func (*MsgStakeholder) GetLastUpdatedHTTPTimeString

func (stakeholder *MsgStakeholder) GetLastUpdatedHTTPTimeString() string

GetLastUpdatedHTTPTimeString exposes the string rep of the last modified timestamp for the object

type Post

type Post interface {
	Post(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Post represents POST Method Call to a resource

type ProducerController

type ProducerController struct {
	ProducerRepo storage.ProducerRepository
}

ProducerController is for /producer/:prodId

func NewProducerController

func NewProducerController(producerRepo storage.ProducerRepository) *ProducerController

NewProducerController initialize new producers controller

func (prodController *ProducerController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*ProducerController) Get

func (prodController *ProducerController) Get(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Get implements the /producer/:prodId GET endpoint

func (*ProducerController) GetPath

func (prodController *ProducerController) GetPath() string

GetPath returns the endpoint's path

func (*ProducerController) Put

func (prodController *ProducerController) Put(w http.ResponseWriter, r *http.Request, param httprouter.Params)

Put implements the /producer/:prodId PUT endpoint

type ProducersController

type ProducersController struct {
	ProducerRepo     storage.ProducerRepository
	ProducerEndpoint EndpointController
}

ProducersController for handling `/producers` endpoint

func NewProducersController

func NewProducersController(producerRepo storage.ProducerRepository, producerController *ProducerController) *ProducersController

NewProducersController initialize new producers controller

func (prodController *ProducersController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*ProducersController) Get

func (prodController *ProducersController) Get(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

Get implements the /producers endpoint

func (*ProducersController) GetPath

func (prodController *ProducersController) GetPath() string

GetPath returns the endpoint's path

type Put

type Put interface {
	Put(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Put represents PUT Method Call to a resource

type ServerLifecycleListener

type ServerLifecycleListener interface {
	StartingServer()
	ServerStartFailed(err error)
	ServerShutdownCompleted()
}

ServerLifecycleListener listens to key server lifecycle error

type StatusController

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

StatusController is the controller for `/_status` endpoint

func NewStatusController

func NewStatusController(appRepo storage.AppRepository) *StatusController

NewStatusController Factory for new StatusController

func (cont *StatusController) FormatAsRelativeLink(params ...httprouter.Param) string

FormatAsRelativeLink Format as relative URL of this resource based on the params

func (*StatusController) Get

Get is the GET /_status endpoint controller

func (*StatusController) GetPath

func (cont *StatusController) GetPath() string

GetPath returns the endpoint path

Jump to

Keyboard shortcuts

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