router

package
Version: v0.0.0-...-7f90a9e Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: MIT Imports: 22 Imported by: 0

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 *log.Logger, 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) 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 (router *ServiceRouter) NewService(service 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) SetLogger

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

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

Source Files

Jump to

Keyboard shortcuts

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