Skip to content

Commit

Permalink
fix: deleted repeating code (#11)
Browse files Browse the repository at this point in the history
refactor repeating code
  • Loading branch information
batuhan authored and bcoe committed Jun 5, 2016
1 parent 5249246 commit 99b6ca0
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
const parallel = require('async').parallel
const ipRangeCheck = require('ip-range-check')
const azure = require('./lib/azure')
const aws = require('./lib/aws')
const gce = require('./lib/gce')
const providers = [
require('./lib/azure'),
require('./lib/aws'),
require('./lib/gce')
]
const whois = require('./lib/whois')

function WhichCloud (ip, done) {
var name = WhichCloud.default
parallel([
function (cb) {
check(ip, azure(), function (err, _name) {
if (err) return cb(err)
else {
if (_name) name = _name
return cb()
}
function checkersGenerator (ip) {
const checkers = []
providers.forEach(function (provider) {
checkers.push(function (cb) {
check(ip, provider(), function (err, _name) {
if (err) return cb(err)
else {
if (_name) name = _name
return cb()
}
})
})
},
function (cb) {
check(ip, aws(), function (err, _name) {
if (err) return cb(err)
else {
if (_name) name = _name
return cb()
}
})
},
function (cb) {
check(ip, gce(), function (err, _name) {
if (err) return cb(err)
else {
if (_name) name = _name
return cb()
}
})
}
], function (err) {
})
return checkers
}

parallel(checkersGenerator(ip), function (err) {
if (err) return done(err)

if (name === WhichCloud.default) {
Expand Down

0 comments on commit 99b6ca0

Please sign in to comment.