Documentation ¶
Overview ¶
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.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
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 ¶
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 ¶
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 ¶
Do sends an HTTP request to a service and returns an HTTP response. URLs for requests use the following format:
sleuth://service-name/requested-path
For example, a request to the path /bar?baz=qux of a service called foo-service would have the URL:
sleuth://foo-service/bar?baz=qux
type Config ¶
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 ¶
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.
Example ¶
package main import ( "fmt" "github.com/FLAGlab/sleuth" ) func main() { config := &sleuth.Config{Interface: "bad"} if _, err := sleuth.New(config); err != nil { fmt.Printf("%v", err.(*sleuth.Error).Codes) } }
Output: [905 901]