1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { Resolver, ResolverListener, registerResolver } from './resolver';
|
18 | import { Endpoint } from './subchannel-address';
|
19 | import { GrpcUri } from './uri-parser';
|
20 | import { ChannelOptions } from './channel-options';
|
21 |
|
22 | class UdsResolver implements Resolver {
|
23 | private hasReturnedResult = false;
|
24 | private endpoints: Endpoint[] = [];
|
25 | constructor(
|
26 | target: GrpcUri,
|
27 | private listener: ResolverListener,
|
28 | channelOptions: ChannelOptions
|
29 | ) {
|
30 | let path: string;
|
31 | if (target.authority === '') {
|
32 | path = '/' + target.path;
|
33 | } else {
|
34 | path = target.path;
|
35 | }
|
36 | this.endpoints = [{ addresses: [{ path }] }];
|
37 | }
|
38 | updateResolution(): void {
|
39 | if (!this.hasReturnedResult) {
|
40 | this.hasReturnedResult = true;
|
41 | process.nextTick(
|
42 | this.listener.onSuccessfulResolution,
|
43 | this.endpoints,
|
44 | null,
|
45 | null,
|
46 | null,
|
47 | {}
|
48 | );
|
49 | }
|
50 | }
|
51 |
|
52 | destroy() {
|
53 |
|
54 | }
|
55 |
|
56 | static getDefaultAuthority(target: GrpcUri): string {
|
57 | return 'localhost';
|
58 | }
|
59 | }
|
60 |
|
61 | export function setup() {
|
62 | registerResolver('unix', UdsResolver);
|
63 | }
|