utils

package
v0.0.0-...-b77daef Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnError

func OnError(writer http.ResponseWriter, code int, message string)

Wrapper function which calls SendJSONResponse with the provided error code and specifies an error message in the response

func OnSuccess

func OnSuccess(writer http.ResponseWriter, payload interface{})

Wrapper function which calls SendJSONResponse with http.StatusOk

func SendJSONResponse

func SendJSONResponse(writer http.ResponseWriter, code int, payload interface{})

Writes a json response with the specified error code and supplied payload An error is logged if the write fails

func Start

func Start(serverContext *config.Context, router *mux.Router)

Starts the http server supplied in the serverContext in a separate go-routine

func Stop

func Stop(serverContext *config.Context)

Shuts the http server supplied in the serverContext down

func WaitForStopSignal

func WaitForStopSignal() chan os.Signal

Returns a channel that sends a signal when one of the following system calls is detected:

  • SIGHUP
  • SIGINT
  • SIGTERM
  • SIGKILL
  • SIGQUIT

Types

type SMTPBackEnd

type SMTPBackEnd struct {
	Config config.SMTP

	SMTPServer *smtp.Server
	// contains filtered or unexported fields
}

The backend that implements SMTP server methods

func NewSMTPBackEnd

func NewSMTPBackEnd(serverConfig config.SMTP) *SMTPBackEnd

Default constructor for SMTPBackEnd

func (*SMTPBackEnd) AddEmail

func (smtpBackEnd *SMTPBackEnd) AddEmail(email parsemail.Email)

Adds an email to the queue Uses a mutex to ensure thread safety.

func (*SMTPBackEnd) AnonymousLogin

func (smtpBackEnd *SMTPBackEnd) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error)

AnonymousLogin requires clients to authenticate using SMTP AUTH before sending emails

func (*SMTPBackEnd) ClearEmails

func (smtpBackEnd *SMTPBackEnd) ClearEmails()

Removes all emails from the queue Uses a mutex for thread safety.

func (*SMTPBackEnd) GetEmail

func (smtpBackEnd *SMTPBackEnd) GetEmail() (parsemail.Email, error)

Retrieves the first email and removes it from the queue Uses a mutex to ensure thread safety.

func (*SMTPBackEnd) Login

func (smtpBackEnd *SMTPBackEnd) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error)

Login handles a login command with username and password.

func (*SMTPBackEnd) Start

func (smtpBackEnd *SMTPBackEnd) Start()

Starts the SMTPServer in a new go-routine

func (*SMTPBackEnd) Stop

func (smtpBackEnd *SMTPBackEnd) Stop()

Calls close on a running SMTPServer instance

type Session

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

A Session is returned after successful login.

func (*Session) Data

func (s *Session) Data(reader io.Reader) error

Data is parsed and is added to the email queue

func (*Session) Logout

func (s *Session) Logout() error

func (*Session) Mail

func (s *Session) Mail(from string, opts smtp.MailOptions) error

func (*Session) Rcpt

func (s *Session) Rcpt(to string) error

func (*Session) Reset

func (s *Session) Reset()

Jump to

Keyboard shortcuts

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