sleuth: Index | Examples | Files

package sleuth

import ""

Package sleuth provides master-less peer-to-peer autodiscovery and RPC between HTTP services that reside on the same network. It works with minimal configuration and provides a mechanism to join a local network both as a client that offers no services and as any service that speaks HTTP. Its primary use case is for microservices on the same network that make calls to one another.



Package Files

client.go config.go destination.go error.go notifier.go peer.go pool.go request.go response.go sleuth.go workers.go writer.go zip.go

type Client Uses

type Client struct {
    // Timeout is the duration to wait before an outstanding request times out.
    // By default, it is set to 500ms.
    Timeout time.Duration
    // contains filtered or unexported fields

Client is the peer on the sleuth network that makes requests and, if a handler has been provided, responds to peer requests.

func New Uses

func New(config *Config) (*Client, error)

New is the entry point to the sleuth package. It returns a reference to a Client object that has joined the local network. If the config argument is nil, sleuth will use sensible defaults. If the Handler attribute of the config object is not set, sleuth will operate in client-only mode.

func (*Client) Close Uses

func (c *Client) Close() error

Close leaves the sleuth network and stops the Gyre node. It can only be called once, even if it returns an error the first time it is called.

func (*Client) Do Uses

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request to a service and returns an HTTP response. URLs for requests use the following format:


For example, a request to the path /bar?baz=qux of a service called foo-service would have the URL:


func (*Client) WaitFor Uses

func (c *Client) WaitFor(services ...string) error

WaitFor blocks until the required services are available to the client.

type Config Uses

type Config struct {

    // Handler is the HTTP handler for a service made available via sleuth.
    Handler http.Handler `json:"-"`

    // Interface is the system network interface sleuth should use, e.g. "en0".
    Interface string `json:"interface,omitempty"`

    // LogLevel is the ursiform.Logger level for sleuth. The default is "silent".
    // The options, in order of increasing verbosity, are:
    // "silent"    No log output at all.
    // "error"     Only errors are logged.
    // "blocked"   Blocking calls and lower are logged.
    // "unblocked" Unblocked notifications and lower are logged.
    // "warn"      Warnings and lower are logged.
    // "reject"    Rejections (e.g., in a firewall) and lower are logged.
    // "listen"    Listeners and lower are logged.
    // "install"   Install notifications and lower are logged.
    // "init"      Initialization notifications and lower are logged.
    // "request"   Incoming requests and lower are logged.
    // "info"      Info output and lower are logged.
    // "debug"     All log output is shown.
    LogLevel string `json:"loglevel,omitempty"`

    // Port is the UDP port that sleuth should broadcast on. The default is 5670.
    Port int `json:"port,omitempty"`

    // Service is the name of the service being offered if a Handler exists.
    Service string `json:"service,omitempty"`

    // Version is the optional version string of the service being offered.
    Version string `json:"version,omitempty"`
    // contains filtered or unexported fields

Config is the configuration specification for sleuth client instantiation. It has JSON tag values defined for all public fields except Handler in order to allow users to store sleuth configuration in JSON files. All fields are optional, but Interface is particularly important to guarantee all peers reside on the same subnet.

type Error Uses

type Error struct {
    // Codes contains the list of error codes that led to a specific error.
    Codes []int
    // contains filtered or unexported fields

Error is the type all sleuth errors can be asserted as in order to query the error code trace that resulted in any particular error.


config := &sleuth.Config{Interface: "bad"}
if _, err := sleuth.New(config); err != nil {
    fmt.Printf("%v", err.(*sleuth.Error).Codes)


[905 901]

func (*Error) Error Uses

func (e *Error) Error() string

Error returns an error string.

Package sleuth imports 12 packages (graph). Updated 2019-03-12. Refresh now. Tools for package owners.