-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
43 lines (39 loc) · 974 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var idgen = require('idgen');
function Spec(set) {
if (set) {
if (typeof set === 'string') {
set = {service: set};
}
// Parse a version out of service
if (set.service && set.service.indexOf('@') !== -1) {
var parts = set.service.split('@');
this.service = parts[0];
this.version = parts[1];
delete set.service;
}
var self = this;
Object.keys(set).forEach(function (k) {
self[k] = set[k];
});
}
if (!this.id) {
this.id = idgen();
}
}
Spec.prototype.toString = function() {
if (this.version) {
return this.service + '[v' + this.version + ']@' + this.host + ':' + this.port;
}
else if (this.service) {
return this.service + '@' + this.host + ':' + this.port;
}
else if (this.host && this.port) {
return this.host + ':' + this.port;
}
return this.id;
};
module.exports = exports = Spec;
exports.attach = function (options) {
var amino = this;
amino.Spec = Spec;
};