Documentation ¶
Index ¶
Constants ¶
const ( // ProviderTimeout should be used by all callers for calles to `Images` ProviderTimeout = 500 * time.Millisecond )
Variables ¶
var ( ErrImageNotFound = errors.New("image not found") // ErrImagesDone is used to stop iteration of subsequent images. It should be // returned from forEachFunc when either the intended image has been found or // the maximum number of images has been iterated. ErrImagesDone = errors.New("images done") // ErrImagesNoPath is returned whenever an image is found but has no path on disk. ErrImagesNoPath = errors.New("no path for image") // ErrImagesNoURL is returned whenever an image is found but has no URL. ErrImagesNoURL = errors.New("no URL for image") // ErrNoImageForAlert is returned when no image is associated to a given alert. ErrNoImageForAlert = errors.New("no image for alert") )
Functions ¶
func WithStoredImages ¶
func WithStoredImages(ctx context.Context, l logging.Logger, imageProvider Provider, forEachFunc forEachImageFunc, alerts ...*types.Alert) error
WithStoredImages retrieves the image for each alert and then calls forEachFunc with the index of the alert and the retrieved image struct. If the alert does not have an image token, or the image does not exist then forEachFunc will not be called for that alert. If forEachFunc returns an error, WithStoredImages will return the error and not iterate the remaining alerts. A forEachFunc can return ErrImagesDone to stop the iteration of remaining alerts if the intended image or maximum number of images have been found.
Types ¶
type FakeProvider ¶
func (*FakeProvider) GetImageURL ¶
GetImageURL returns the URL of the image associated with a given alert.
func (*FakeProvider) GetRawImage ¶
func (f *FakeProvider) GetRawImage(_ context.Context, alert *types.Alert) (io.ReadCloser, string, error)
GetRawImage returns an io.Reader to read the bytes of the image associated with a given alert.
type Provider ¶
type Provider interface { // GetImage takes a token (identifier) and returns the image that token belongs to. // Returns `ErrImageNotFound` if there's no image for said token. // // Deprecated: This method will be removed when all integrations use GetImageURL and/or GetRawImage, // which allow integrations to get just the data they need for adding images to notifications. // Use any of those two methods instead. GetImage(ctx context.Context, token string) (*Image, error) // GetImageURL returns the URL of an image associated with a given alert. // - Returns `ErrImageNotFound` if no image is found. // - Returns `ErrImagesNoURL` if the image doesn't have a URL. GetImageURL(ctx context.Context, alert *types.Alert) (string, error) // GetRawImage returns an io.Reader to read the bytes of an image associated with a given alert // and a string representing the filename. // - Returns `ErrImageNotFound` if no image is found. // - Returns `ErrImagesNoPath` if the image doesn't have a path on disk. GetRawImage(ctx context.Context, alert *types.Alert) (io.ReadCloser, string, error) }
func NewFakeProvider ¶
NewFakeProvider returns an image provider with N test images. Each image has a token and a URL, but does not have a file on disk.
func NewFakeProviderWithFile ¶
NewFakeProviderWithFile returns an image provider with N test images. Each image has a token, path and a URL, where the path is 1x1 transparent PNG on disk. The test should call deleteFunc to delete the images from disk at the end of the test. nolint:deadcode,unused
type UnavailableProvider ¶
type UnavailableProvider struct{}
func (*UnavailableProvider) GetImage ¶
GetImage returns the image with the corresponding token, or ErrImageNotFound.
func (*UnavailableProvider) GetImageURL ¶
func (*UnavailableProvider) GetRawImage ¶
func (u *UnavailableProvider) GetRawImage(context.Context, *types.Alert) (io.ReadCloser, string, error)