firewheel

package module
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 1 Imported by: 0

README

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("test@gmail.com"),
      email.To("test@gmail.com", "example@gmail.com"),
      email.Bcc("example@gmail.com"),
      email.Cc("example@gmail.com"),
    ); 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("test@gmail.com"),
    		email.To("example@gmail.com"),
    		email.Bcc("example@gmail.com"),
    		email.Cc("example@gmail.com"),
    	)
    

    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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Messager

type Messager interface {
	// Sender requires send ability.
	Sender

	// Setup binds sender.
	Setup(...Sender)
}

Messager binds sender and indicates where the data source come from.

type Option

type Option interface {
	// Apply it-self recursively.
	Apply(Option) Option
}

Option is the way allowed caller offers values they needs.

type Sender

type Sender interface {
	// Send sends message which is the main processor
	// requires io.Reader include message body and
	// several args which implements Option.
	Send(io.Reader, ...Option) error
}

Sender provides message delivery ability.

Directories

Path Synopsis
Package sender currently provides Mail, DingTalk WeChat and etc.
Package sender currently provides Mail, DingTalk WeChat and etc.
dingding
Package dingding provides sending message ability on DingTalk platform.
Package dingding provides sending message ability on DingTalk platform.
email
Package email provides sending email ability.
Package email provides sending email ability.
wechat
Package wechat provides sending message ability on WeChat.
Package wechat provides sending message ability on WeChat.

Jump to

Keyboard shortcuts

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