senders

package
v0.0.0-...-de41a1e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpSenderType        senderType        = "http-sender"
	MattermostSenderType  senderType        = "mattermost"
	SingleMessageFormat   pushMessageFormat = "single"
	MultipleMessageFormat pushMessageFormat = "multi"
)
View Source
const ApplicationJson = "application/json"

Variables

This section is empty.

Functions

func DetermineMessageFormat

func DetermineMessageFormat(numberOfMessages int64) pushMessageFormat

DetermineMessageFormat decides what message format should be used depending on the number of messages

Types

type HttpSender

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

HttpSender delivers data to any http endpoint

func NewHttpSender

func NewHttpSender(endpoint, authz string, client *http.Client) *HttpSender

NewHttpSender initialises and returns a new http sender

func (*HttpSender) Destination

func (s *HttpSender) Destination() string

Destination returns the http endpoint where data is being sent

func (*HttpSender) Send

func (s *HttpSender) Send(ctx context.Context, msgs PushMsgs, format pushMessageFormat) error

Send delivers a message to remote http endpoint

type MattermostError

type MattermostError struct {
	Id            string `json:"id"`
	Message       string `json:"message"`
	DetailedError string `json:"detailed_error"`
	RequestId     string `json:"request_id"`
	StatusCode    int    `json:"status_code"`
}

func (*MattermostError) Error

func (m *MattermostError) Error() string

type MattermostMessage

type MattermostMessage struct {
	Text     string `json:"text"`
	Username string `json:"username,omitempty"`
	Channel  string `json:"channel,omitempty"`
}

type MattermostSender

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

HttpSender delivers data to any http endpoint

func NewMattermostSender

func NewMattermostSender(webhookUrl, username, channel string, client *http.Client) *MattermostSender

NewMattermostSender initialises and returns a new mattermost sender

func (*MattermostSender) Destination

func (s *MattermostSender) Destination() string

Destination returns the http webhook where data is being sent

func (*MattermostSender) Send

func (s *MattermostSender) Send(ctx context.Context, msgs PushMsgs, format pushMessageFormat) error

Send delivers a message to a remote mattermost webhook url

type MockMattermostRoundTripper

type MockMattermostRoundTripper struct {
	RequestBodyBytes []byte
	Message          MattermostMessage
}

func (*MockMattermostRoundTripper) RoundTrip

type MockSender

type MockSender struct {
	SendStatus   string
	PushMessages []PushMsg
}

func (*MockSender) Destination

func (s *MockSender) Destination() string

func (*MockSender) Send

func (s *MockSender) Send(ctx context.Context, msgs PushMsgs, format pushMessageFormat) error

type MockSenderRoundTripper

type MockSenderRoundTripper struct {
	RequestBodyBytes []byte
}

func (*MockSenderRoundTripper) RoundTrip

func (m *MockSenderRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

type PushMsg

type PushMsg struct {
	// the actual message
	Msg ams.Message `json:"message"`
	// the source
	Sub string `json:"subscription"`
}

PushMsg holds data to be send to a remote endpoint

type PushMsgs

type PushMsgs struct {
	// the actual messages
	Messages []PushMsg `json:"messages"`
}

PushMsgs holds data to be send to a remote endpoint(multiple messages grouped together)

type Sender

type Sender interface {
	// Send sends the data to a remote destination
	Send(ctx context.Context, msgs PushMsgs, format pushMessageFormat) error
	// Destination returns the target destination where the sender sends the data
	Destination() string
}

Sender is responsible for delivering data to remote destinations

func New

func New(cfg amsPb.PushConfig, client *http.Client) (Sender, error)

New acts as a sender factory, creates and returns a new sender based on the provided type

Jump to

Keyboard shortcuts

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