Created
October 31, 2017 00:46
-
-
Save gnilchee/6f6abb08c52282ecac9434e282bea514 to your computer and use it in GitHub Desktop.
Crystal-Lang example using http/client, logger and option_parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "http/client" | |
require "option_parser" | |
require "logger" | |
destination = "changeme" | |
help = "" | |
log = Logger.new(STDOUT) | |
log.level = Logger::INFO | |
OptionParser.parse! do |parser| | |
parser.banner = "Usage: #{PROGRAM_NAME} (-d NAME | --destination=NAME)" | |
parser.on("-d NAME", "--destination=NAME", "Defines endpoint to inspect (prod-1 or prod-2)") { |name| destination = name} | |
parser.on("-h", "--help", "Show this help") { puts parser } | |
end | |
if destination == "changeme" | |
log.error("Please supply a valid endpoint to test!") | |
exit 1 | |
end | |
resp = HTTP::Client.get "http://#{destination}.example.io/api/master" | |
if resp.status_code == 200 && resp.body == "true" | |
log.info("Yes, #{destination} is master") | |
exit 0 | |
else | |
log.warn("No, #{destination} is NOT master") | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment