sns

package
v0.0.0-...-cb67029 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/xumak-grid/go-grid/pkg/notifications/sns"
)

type Message struct {
	Message string `json:"message"`
	Value   int    `json:"value"`
}

func main() {
	session, err := sns.NewSessionWithCredentials("XXXX", "XXXX", "us-east-1")
	if err != nil {
		fmt.Println("session error:", err)
		return
	}

	notify := sns.Notify{
		Subject:  "Bedrock deployment",
		TopicArn: "arn:aws:sns:us-east-1:281327226678:toolbelt_notification",
		Session:  session,
	}

	type Message struct {
		Message string `json:"message"`
	}

	t := Message{"Toolbelt deployment success "}
	notify.AddNotification("toolbelt", t)

	k := Message{"k8s deplotment success"}
	notify.AddNotification("k8s", k)

	// publish all the messages
	err = notify.Publish()
	if err != nil {
		fmt.Println(err.Error())
	}
}
Output:

Index

Examples

Constants

View Source
const (
	MessageStructureRaw = "raw"
)

Variables

This section is empty.

Functions

func NewSessionWitToken

func NewSessionWitToken(id, secret, token, region string) (*session.Session, error)

NewSessionWitToken returns a new AWS session with the values provided

func NewSessionWithCredentials

func NewSessionWithCredentials(accessKeyID, secretAccessKey, region string) (*session.Session, error)

NewSessionWithCredentials returns a new AWS session with the values provided

func NewSessionWithProfile

func NewSessionWithProfile(region, profile string) (*session.Session, error)

NewSessionWithProfile returns a new AWS session with the values provided

Types

type Notify

type Notify struct {
	Subject  string                 `json:"-"`
	Messages map[string]interface{} `json:"messages"`
	TopicArn string                 `json:"-"`
	Session  *session.Session       `json:"-"`
}

Notify represents a SNS notification

func (*Notify) AddNotification

func (n *Notify) AddNotification(name string, message interface{}) error

AddNotification adds notifications message to the Notify Messages map this addition does not override the messages already saved

func (*Notify) Publish

func (n *Notify) Publish() error

Publish publishes the messages with the values provided the Messages are marshaled to get a JSON string value

Jump to

Keyboard shortcuts

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