Giter Site home page Giter Site logo

firewheel's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.