mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-21 10:26:26 +00:00
add unix socket support
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
23370fd04d
commit
b230278441
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.idea
|
||||
.bin
|
||||
/tmp
|
||||
|
@ -43,11 +43,16 @@ func New(opts ...Option) (Client, error) {
|
||||
if len(c.opts.streamInterceptors) > 0 {
|
||||
c.opts.dialOptions = append(c.opts.dialOptions, grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(c.opts.streamInterceptors...)))
|
||||
}
|
||||
if c.opts.addr == "" {
|
||||
switch {
|
||||
case c.opts.addr == "":
|
||||
c.addr = fmt.Sprintf("%s:///%s", c.opts.registry.String(), c.opts.name)
|
||||
} else if strings.HasPrefix(c.opts.addr, "tcp://") {
|
||||
case strings.HasPrefix(c.opts.addr, "tcp://"):
|
||||
c.addr = strings.Replace(c.opts.addr, "tcp://", "", 1)
|
||||
} else {
|
||||
case strings.HasPrefix(c.opts.addr, "unix:///"):
|
||||
c.addr = c.opts.addr
|
||||
case strings.HasPrefix(c.opts.addr, "unix://"):
|
||||
c.addr = strings.Replace(c.opts.addr, "unix://", "unix:", 1)
|
||||
default:
|
||||
c.addr = c.opts.addr
|
||||
}
|
||||
if c.opts.version != "" && c.opts.addr == "" {
|
||||
|
@ -145,7 +145,13 @@ func (s *service) run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
lis, err := net.Listen("tcp", s.opts.address)
|
||||
network := "tcp"
|
||||
if strings.HasPrefix(s.opts.address, "unix://") {
|
||||
network = "unix"
|
||||
s.opts.address = strings.TrimPrefix(s.opts.address, "unix://")
|
||||
}
|
||||
|
||||
lis, err := net.Listen(network, s.opts.address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user