Skip to content

llianc62/firewheel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

firewheel

Build Status codecov PkgGoDev CodeFactor GitHub

Package firewheel defines a message delivery model, provides various platform warpped sdk, such as Email, DingTalk, WeChat and etc.

Features:

  • Email
  • DingTalk
  • WeChat

Installation

go get -u github.com/LiangXianSen/firewheel

Guide

firewheel is well designed as out-of-the-box, you can send message by Sender which you choose, or implements a Messager, sets up multiple senders.

Simply usage:

package main

import (
	"log"
	"strings"

	fw "github.com/LiangXianSen/firewheel"
	"github.com/LiangXianSen/firewheel/sender/email"
)

func main() {
    var err error
    var sender fw.Sender

    if sender, err = email.NewSender(
      "smtp.gmail.com:587",                     // smtp server
      email.LoginAuth("username", "password"),  // smtp.Auth 
    ); err != nil {
      log.Fatal(err)
    }

    if err = sender.Send(
      strings.NewReader("test message"),        // io.Reader include message body
      email.TextContentType(),
      email.Subject("email test"),
      email.From("[email protected]"),
      email.To("[email protected]", "[email protected]"),
      email.Bcc("[email protected]"),
      email.Cc("[email protected]"),
    ); err != nil {
      log.Fatal(err)
    }
}

there are some tips:

  • You can gives all options when new a sender, use each Send() function will include all options once you provided. On condition that you don't usually change.

    sender, err = email.NewSender(
    		"smtp.gmail.com:587",
    		email.LoginAuth("username", "password"),
    		email.TextContentType(),
    		email.Subject("email test"),
    		email.From("[email protected]"),
    		email.To("[email protected]"),
    		email.Bcc("[email protected]"),
    		email.Cc("[email protected]"),
    	)

    or at some conditions change some of them.

    sender.Send(
    	strings.NewReader("test message"),
    	email.Subjectc("new email test"),
    )
  • sends message with dynamic subject:

    sender, err = email.NewSender(
    	        "smtp.gmail.com:587",
    	        email.LoginAuth("username", "password"),
    	        email.TextContentType(),
    	        email.SubjectFunc(func() string {
    	        	date := time.Now().Format("2016-01-02 15:04:05")
    	        	return "test date: " + date
    	        })
    	)

Massager pattern:

You also can implements Massager , sets up few senders. Sends one mssage to different destination. see examples