-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
39 lines (32 loc) · 899 Bytes
/
util.go
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
package mdnsresolver
import (
"errors"
"strings"
"google.golang.org/grpc/resolver"
)
type targetInfo struct {
instanceName string
serviceName string
domain string
target resolver.Target
}
func parseResolverTarget(target resolver.Target) (*targetInfo, error) {
// mdns://serviceName/serviceInstanceName.domain
endpoint := target.Endpoint
authority := target.Authority
if authority == "" {
return nil, errors.New("Could not parse target. Invalid Authority")
}
if endpoint == "" {
return nil, errors.New("Could not parse target. Invalid Endpoint")
}
ti := &targetInfo{target: target}
parts := strings.Split(endpoint, ".")
if len(parts) == 2 {
ti.instanceName = parts[0]
ti.serviceName = authority
ti.domain = parts[1]
return ti, nil
}
return nil, errors.New("Could not parse target. Invalid Endpoint. Could not find domain and serviceInstanceName")
}