Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active August 29, 2015 14:07
Show Gist options
  • Save tkuchiki/02ba3c70abc76f8953d5 to your computer and use it in GitHub Desktop.
Save tkuchiki/02ba3c70abc76f8953d5 to your computer and use it in GitHub Desktop.
ruby の net/http で consul の status/leader の結果を取得する
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('http://127.0.0.1:8500/v1/status/leader')
http = Net::HTTP.new(uri.host, uri.port)
res = http.start {
http.get(uri.request_uri)
}
if res.code == '200'
result = res.body.delete('"')
else
result = nil
end
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment