From 0ae7f5f7fc26b9b563be4071acc135673d9e49df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Martins?= Date: Mon, 11 Jul 2016 15:29:20 +0100 Subject: [PATCH] Added unix socket example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Martins --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 3e2d2629..bd2f6b0b 100644 --- a/README.md +++ b/README.md @@ -523,6 +523,27 @@ resty.SetContentLength(true) resty.SetError(&Error{}) // or resty.SetError(Error{}) ``` +#### Unix Socket + +```go +unixSocket := "unix:///var/run/my_socket.sock" + +// Create a Go's http.Transport so we can set it in resty. +transport := http.Transport{ + Dial: func(_, _ string) (net.Conn, error) { + return net.Dial("unix", unixSocket) + }, +} + +// Set the previous transport that we created, set the scheme of the communication to the +// socket and set the unixSocket as the HostURL. +r := resty.New().SetTransport(transport).SetScheme("http").SetHostURL(unixSocket) + +// No need to write the host's URL on the request, just the path. +r.R().Get("/index.html") + +``` + ## Versioning resty releases versions according to [Semantic Versioning](http://semver.org)