notifier

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 7 Imported by: 0

README

notifier

CI

notifier is a simple Go library to send notification to other applications.

Feature

Provider Code
DingTalk provider/dingtalk
Bark provider/bark
Lark provider/lark
Feishu provider/feishu
Server 酱 provider/serverchan

Install

go get -u github.com/moond4rk/notifier

Usage

package main

import (
	"os"

	"github.com/moond4rk/notifier"
)

func main() {
	var (
		dingtalkToken     = os.Getenv("dingtalk_token")
		dingtalkSecret    = os.Getenv("dingtalk_secret")
		barkKey           = os.Getenv("bark_key")
		barkServer        = notifier.DefaultBarkServer
		feishuToken       = os.Getenv("feishu_token")
		feishuSecret      = os.Getenv("feishu_secret")
		larkToken         = os.Getenv("lark_token")
		larkSecret        = os.Getenv("lark_secret")
		serverChanUserID  = "" // server chan's userID could be empty
		serverChanSendKey = os.Getenv("server_chan_send_key")
	)
	notifier := notifier.New(
		notifier.WithDingTalk(dingtalkToken, dingtalkSecret),
		notifier.WithBark(barkKey, barkServer),
		notifier.WithFeishu(feishuToken, feishuSecret),
		notifier.WithLark(larkToken, larkSecret),
		notifier.WithServerChan(serverChanUserID, serverChanSendKey),
	)

	var (
		subject = "this is subject"
		content = "this is content"
	)
	if err := notifier.Send(subject, content); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	// DefaultBarkServer is the default bark server domain
	// more info: https://day.app/2018/06/bark-server-document/
	DefaultBarkServer = "api.day.app"
)

Variables

View Source
var (
	ErrSendNotification = errors.New("send notification")
	ErrNoProvider       = errors.New("no provider, please check your config")
)

Functions

This section is empty.

Types

type Notifier

type Notifier struct {
	Providers []provider
}

func New

func New(options ...Option) *Notifier

func (*Notifier) Send

func (n *Notifier) Send(subject, content string) error

type Option

type Option func(p *Notifier)

func WithBark

func WithBark(key, server string) Option

func WithDingTalk

func WithDingTalk(token, secret string) Option

func WithFeishu

func WithFeishu(token, secret string) Option

func WithLark

func WithLark(token, secret string) Option

func WithServerChan added in v0.1.1

func WithServerChan(userID, sendKey string) Option

Directories

Path Synopsis
_example
internal
provider

Jump to

Keyboard shortcuts

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