router

package
Version: v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: MIT Imports: 24 Imported by: 4

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServiceRouter

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

func New(logger t.StdLogger, serviceURLs ...string) (*ServiceRouter, error)

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

Example
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) AddService added in v0.4.3

func (router *ServiceRouter) AddService(serviceURL string) error

AddService initializes the specified service from its URL, and adds it if no errors occur

func (*ServiceRouter) Enqueue

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

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

Example
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

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

ExtractServiceName from a notification URL

func (*ServiceRouter) Flush

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

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

ListServices returns the available services

func (*ServiceRouter) Locate

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

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

func (*ServiceRouter) NewService

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

NewService returns a new uninitialized service instance

func (*ServiceRouter) Route

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

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

func (*ServiceRouter) Send

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

Send sends the specified message using the routers underlying services

func (*ServiceRouter) SendAsync

func (router *ServiceRouter) SendAsync(message string, params *t.Params) chan error

SendAsync sends the specified message using the routers underlying services

func (*ServiceRouter) SendItems added in v0.4.0

func (router *ServiceRouter) SendItems(items []t.MessageItem, params t.Params) []error

SendItems sends the specified message items using the routers underlying services

func (*ServiceRouter) SetLogger

func (router *ServiceRouter) SetLogger(logger t.StdLogger)

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

Jump to

Keyboard shortcuts

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