control

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONToProto

func JSONToProto(channel *Channel) (protoChan *protoed.Channel)

JSONToProto converts a parsed JSON channel to the protobuf channel representation.

JSONToProto requires: * channel != nil

JSONToProto ensures: * protoChan != nil

func SetupRouter

func SetupRouter(h Handler) *mux.Router

SetupRouter sets up a router. If you don't use any middleware, you are good to go. Otherwise, you need to maually re-implement this function with your middlewares.

func ValidateAgainstChannelSchema

func ValidateAgainstChannelSchema(bb []byte) error

ValidateAgainstChannelSchema validates a message coming from the client against Channel schema.

func ValidateAgainstChannelsPageSchema

func ValidateAgainstChannelsPageSchema(bb []byte) error

ValidateAgainstChannelsPageSchema validates a message coming from the client against ChannelsPage schema.

func ValidateAgainstDescriptorSchema

func ValidateAgainstDescriptorSchema(bb []byte) error

ValidateAgainstDescriptorSchema validates a message coming from the client against Descriptor schema.

func ValidateAgainstEntitySchema

func ValidateAgainstEntitySchema(bb []byte) error

ValidateAgainstEntitySchema validates a message coming from the client against Entity schema.

func ValidateAgainstTokenSchema

func ValidateAgainstTokenSchema(bb []byte) error

ValidateAgainstTokenSchema validates a message coming from the client against Token schema.

func WrapDeleteChannel

func WrapDeleteChannel(h Handler, w http.ResponseWriter, r *http.Request)

WrapDeleteChannel wraps the path `/api/channel` with the method "delete"

Path description: removes the channel associated with the descriptor.

func WrapListChannels

func WrapListChannels(h Handler, w http.ResponseWriter, r *http.Request)

WrapListChannels wraps the path `/api/list_channels` with the method "get"

Path description: lists the available channels information.

func WrapPutChannel

func WrapPutChannel(h Handler, w http.ResponseWriter, r *http.Request)

WrapPutChannel wraps the path `/api/channel` with the method "put"

Path description: Updates the channel uniquely identified by a descriptor.

If there is already a channel associated with the descriptor, the old channel is overwritten with the new one.

In order to enforce the min_period between messages, the Relay server keeps track of the time of the most recently relayed message for each descriptor. If a channel is overwritten, the time of relay of the most recent message is erased unless the new channel has the same min_period field as the old one.

Types

type Channel

type Channel struct {
	Descriptor Descriptor `json:"descriptor"`

	Token Token `json:"token"`

	Sender Entity `json:"sender"`

	Recipients []Entity `json:"recipients"`

	Cc []Entity `json:"cc,omitempty"`

	Bcc []Entity `json:"bcc,omitempty"`

	// indicates the MailGun domain for the channel.
	Domain string `json:"domain"`

	// is the minimum push period frequency for a channel, in seconds.
	MinPeriod float32 `json:"min_period"`

	// indicates the maximum allowed size of the request, in bytes.
	MaxSize int32 `json:"max_size"`
}

Channel defines the messaging channel.

func ProtoToJSON

func ProtoToJSON(channel *protoed.Channel) (jsonChan *Channel)

ProtoToJSON converts a protobuf channel to the parsed JSON channel representation.

ProtoToJSON requires: * channel != nil

ProtoToJSON ensures: * jsonChan != nil

type ChannelsPage

type ChannelsPage struct {
	// specifies the index of the page.
	Page int32 `json:"page"`

	// specifies the number of pages available.
	PageCount int32 `json:"page_count"`

	// specifies the number of items per page.
	PerPage int32 `json:"per_page"`

	// contains the channel data.
	Channels []Channel `json:"channels"`
}

ChannelsPage lists channels in a paginated manner.

type Descriptor

type Descriptor string

Descriptor identifies a channel.

type Entity

type Entity struct {
	Email string `json:"email"`

	Name *string `json:"name,omitempty"`
}

Entity contains the email address and optionally the name of an entity.

type Handler

type Handler interface {
	// PutChannel handles the path `/api/channel` with the method "put".
	//
	// Path description:
	// Updates the channel uniquely identified by a descriptor.
	//
	// If there is already a channel associated with the descriptor, the old channel is overwritten with the new one.
	//
	// In order to enforce the min_period between messages, the Relay server keeps track of the time of the most
	// recently relayed message for each descriptor. If a channel is overwritten, the time of relay of the most
	// recent message is erased unless the new channel has the same min_period field as the old one.
	PutChannel(w http.ResponseWriter,
		r *http.Request,
		channel Channel)

	// DeleteChannel handles the path `/api/channel` with the method "delete".
	//
	// Path description:
	// removes the channel associated with the descriptor.
	DeleteChannel(w http.ResponseWriter,
		r *http.Request,
		descriptor Descriptor)

	// ListChannels handles the path `/api/list_channels` with the method "get".
	//
	// Path description:
	// lists the available channels information.
	ListChannels(w http.ResponseWriter,
		r *http.Request,
		page *int32,
		perPage *int32)
}

Handler defines an interface to handling the routes.

type HandlerImpl

type HandlerImpl struct {
	LogErr *log.Logger
	LogOut *log.Logger
	Env    *database.Env
}

HandlerImpl implements the Handler.

func (*HandlerImpl) DeleteChannel

func (h *HandlerImpl) DeleteChannel(w http.ResponseWriter,
	r *http.Request,
	descriptor Descriptor)

DeleteChannel implements Handler.DeleteChannel.

func (*HandlerImpl) ListChannels

func (h *HandlerImpl) ListChannels(w http.ResponseWriter,
	r *http.Request,
	page *int32,
	perPage *int32)

ListChannels implements Handler.ListChannels.

func (*HandlerImpl) PutChannel

func (h *HandlerImpl) PutChannel(w http.ResponseWriter,
	r *http.Request,
	channel Channel)

PutChannel implements Handler.PutChannel.

type Token

type Token string

Token is a string authenticating the sender of an HTTP request.

Jump to

Keyboard shortcuts

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