notifier

package module
v0.0.0-...-18c0eec Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Notifier

Build Status | codecov | Go Report Card | GoDoc

A simple notifier tool.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

With support for

  • Slack

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get
Go
go get github.com/joaosoft/notifier
Configuration
{
  "notifier": {
    "log": {
      "level": "info"
    },
    "slack": {
      "webhook": "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
  }
}

Usage

This examples are available in the project at notifier/examples

func main() {
	myNotifier, err := notifier.New()
	if err != nil {
		panic(err)
	}

	// notifiers
	slack := myNotifier.NewSlackNotifier()

	// send message with slack notifier
	sendMessage(slack, "hello slack")
}

func sendMessage(notifier notifier.INotifier, message string) {
	fmt.Printf("\nSending message to %s...\n\n", notifier.Name())

	if err := notifier.Notify(message); err != nil {
		panic(err)
	}

	fmt.Printf("\nMessage sent to %s!", notifier.Name())
}
Result:
Sending message to slack...

[IN] Method[POST] Url[/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXX] on Start[2019-03-26 21:51:21.943464 +0000 WET m=+0.005795099]
[OUT] Status[200] Method[POST] Url[/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXX] on Start[2019-03-26 21:51:21.943464 +0000 WET m=+0.005795099] Elapsed[565.239383ms]

Message send to slack!

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotifierSendMessage = errors.New(errors.LevelError, 1, "error sending message [notifier: %s, error: %s]")
	ErrorNotifierStatus      = errors.New(errors.LevelError, 1, "error sending message [notifier: %s, status: %d, error: %s]")
	ErrorMarshalMessage      = errors.New(errors.LevelError, 1, "error marshall message [notifier: %s, message: %s]")
)

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Notifier *NotifierConfig `json:"notifier"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type INotifier

type INotifier interface {
	Name() string
	Notify(message string) error
}

type NotificationsOption

type NotificationsOption func(client *Notifier)

NotificationsOption ...

func WithConfiguration

func WithConfiguration(config *NotifierConfig) NotificationsOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) NotificationsOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) NotificationsOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) NotificationsOption

WithManager ...

type Notifier

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

func New

func New(options ...NotificationsOption) (*Notifier, error)

New ...

func (*Notifier) NewSlackNotifier

func (n *Notifier) NewSlackNotifier(config ...*SlackConfig) INotifier

func (*Notifier) Reconfigure

func (n *Notifier) Reconfigure(options ...NotificationsOption)

Reconfigure ...

type NotifierConfig

type NotifierConfig struct {
	Slack *SlackConfig `json:"slack"`
	Log   struct {
		Level string `json:"level"`
	} `json:"log"`
}

NotifierConfig ...

type SlackConfig

type SlackConfig struct {
	Webhook string `json:"webhook"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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