sessrv

package module
v0.0.0-...-8c6d88a Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 6 Imported by: 0

README

CircleCI codecov GoDoc Go Report Card

http-ses-service

The http-ses-service is the lab259/http service for the Amazon Simple Email Service (SES).

It wraps the logic of dealing with credentials and keeping the session.

Dependencies

It depends on the lab259/http (and its dependencies, of course) itself and the aws/aws-sdk-go library.

Installation

First, fetch the library to the repository.

go get github.com/lab259/http-ses-service

Usage

The service is designed to be "extended" and not used directly.

srv.go

package mail

import (
	"github.com/lab259/http"
	"github.com/lab259/http-ses-service"
)

type MailSQSService struct {
	sessrv.SQSService
}

func (service *MailSQSService) LoadConfiguration() (interface{}, error) {
	var configuration sessrv.SQSServiceConfiguration

	configurationLoader := http.NewFileConfigurationLoader("/etc/mail")
	configurationUnmarshaler := &http.ConfigurationUnmarshalerYaml{}

	config, err := configurationLoader.Load("ses.yml")
	if err != nil {
		return err
	}
	return configurationUnmarshaler.Unmarshal(config, dst)
	if err != nil {
		return nil, err
	}
	return configuration, nil
}

example.go

// ...

var mq rscsrsv.MailSQSService

func init() {
	configuration, err := mq.LoadConfiguration()
	if err != nil {
		panic(err)
	}
	err = mq.ApplyConfiguration(configuration)
	if err != nil {
		panic(err)
	}
	err = mq.Start()
	if err != nil {
		panic(err)
	}
}

// sendEmail sends an email using the SES
func sendEmail() {
	err := service.RunWithSES(func (s *ses.SES) error {

		// use the `s` variable to implement sending an email.
		// More info on: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/using-ses-with-go-sdk.html

		return nil
	})
	if err != nil {
		panic(err)
	}
	// ...
}

// ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCredentialsFromStruct

func NewCredentialsFromStruct(credentials *SESServiceConfiguration) *credentialsFromStruct

Types

type SESService

type SESService struct {
	Configuration SESServiceConfiguration
	// contains filtered or unexported fields
}

SESService is the service which manages a service queue on the AWS.

func (*SESService) ApplyConfiguration

func (service *SESService) ApplyConfiguration(configuration interface{}) error

ApplyConfiguration applies a given configuration to the service.

func (*SESService) LoadConfiguration

func (service *SESService) LoadConfiguration() (interface{}, error)

LoadConfiguration returns a not implemented error.

This happens because this method should be implemented on the struct that will use this implementation.

func (*SESService) Restart

func (service *SESService) Restart() error

Restart stops and then starts the service again.

func (*SESService) RunWithSES

func (service *SESService) RunWithSES(handler func(client *ses.SES) error) error

RunWithSQS runs a handler passing the reference of a `sqs.SQS` client.

func (*SESService) Start

func (service *SESService) Start() error

Start initializes the aws client with the configuration.

func (*SESService) Stop

func (service *SESService) Stop() error

Stop erases the aws client reference.

type SESServiceConfiguration

type SESServiceConfiguration struct {
	Endpoint string `yaml:"endpoint"`
	Region   string `yaml:"region"`
	Key      string `yaml:"key"`
	Secret   string `yaml:"secret"`
}

SESServiceConfiguration is the configuration for the `SESService`

Jump to

Keyboard shortcuts

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