shoutrrr: github.com/containrrr/shoutrrr/pkg/router Index | Examples | Files

package router

import "github.com/containrrr/shoutrrr/pkg/router"

Index

Examples

Package Files

router.go

type ServiceRouter Uses

type ServiceRouter struct {
    Timeout time.Duration
    // contains filtered or unexported fields
}

ServiceRouter is responsible for routing a message to a specific notification service using the notification URL

func New Uses

func New(logger *log.Logger, serviceURLs ...string) (*ServiceRouter, error)

New creates a new service router using the specified logger and service URLs

Code:

logger := log.New(os.Stdout, "", 0)
sr, err := New(logger, "logger://")
if err != nil {
    log.Fatalf("could not create router: %s", err)
}
sr.Send("hello", nil)

Output:

hello

func (*ServiceRouter) Enqueue Uses

func (router *ServiceRouter) Enqueue(message string, v ...interface{})

Enqueue adds the message to an internal queue and sends it when Flush is invoked

Code:

logger := log.New(os.Stdout, "", 0)
sr, err := New(logger, "logger://")
if err != nil {
    log.Fatalf("could not create router: %s", err)
}
defer sr.Flush(nil)
sr.Enqueue("hello")
sr.Enqueue("world")

Output:

hello
world

func (*ServiceRouter) ExtractServiceName Uses

func (router *ServiceRouter) ExtractServiceName(rawURL string) (string, *url.URL, error)

ExtractServiceName from a notification URL

func (*ServiceRouter) Flush Uses

func (router *ServiceRouter) Flush(params *t.Params)

Flush sends all messages that have been queued up as a combined message. This method should be deferred!

func (*ServiceRouter) ListServices Uses

func (router *ServiceRouter) ListServices() []string

ListServices returns the available services

func (*ServiceRouter) Locate Uses

func (router *ServiceRouter) Locate(rawURL string) (t.Service, error)

Locate returns the service implementation that corresponds to the given service URL

func (*ServiceRouter) NewService Uses

func (router *ServiceRouter) NewService(service string) (t.Service, error)

NewService returns a new uninitialized service instance

func (*ServiceRouter) Route Uses

func (router *ServiceRouter) Route(rawURL string, message string) error

Route a message to a specific notification service using the notification URL

func (*ServiceRouter) Send Uses

func (router *ServiceRouter) Send(message string, params *t.Params) []error

Send sends the specified message using the routers underlying services

func (*ServiceRouter) SetLogger Uses

func (router *ServiceRouter) SetLogger(logger *log.Logger)

SetLogger sets the logger that the services will use to write progress logs

Package router imports 22 packages (graph) and is imported by 3 packages. Updated 2020-11-05. Refresh now. Tools for package owners.