1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00
go-micro/tunnel/default.go

80 lines
1.2 KiB
Go
Raw Normal View History

2019-08-05 20:41:48 +02:00
package tunnel
import (
"sync"
"github.com/micro/go-micro/transport"
)
type tun struct {
sync.RWMutex
2019-08-06 12:45:25 +02:00
tr transport.Transport
options Options
2019-08-05 20:41:48 +02:00
connected bool
closed chan bool
}
func newTunnel(opts ...Option) Tunnel {
// initialize default options
options := DefaultOptions()
for _, o := range opts {
o(&options)
}
2019-08-06 12:45:25 +02:00
// tunnel transport
tr := newTransport()
2019-08-05 20:41:48 +02:00
t := &tun{
2019-08-06 12:45:25 +02:00
tr: tr,
2019-08-05 20:41:48 +02:00
options: options,
closed: make(chan bool),
}
return t
}
2019-08-06 12:45:25 +02:00
// Id returns tunnel id
2019-08-05 20:41:48 +02:00
func (t *tun) Id() string {
return t.options.Id
}
2019-08-06 12:45:25 +02:00
// Options returns tunnel options
func (t *tun) Options() Options {
return t.options
}
// Address returns tunnel listen address
2019-08-05 20:41:48 +02:00
func (t *tun) Address() string {
return t.options.Address
}
2019-08-06 12:45:25 +02:00
// Transport returns tunnel client transport
2019-08-05 20:41:48 +02:00
func (t *tun) Transport() transport.Transport {
2019-08-06 12:45:25 +02:00
return t.tr
2019-08-05 20:41:48 +02:00
}
2019-08-06 12:45:25 +02:00
// Connect connects establishes point to point tunnel
2019-08-05 20:41:48 +02:00
func (t *tun) Connect() error {
return nil
}
2019-08-06 12:45:25 +02:00
// Close closes the tunnel
2019-08-05 20:41:48 +02:00
func (t *tun) Close() error {
return nil
}
2019-08-06 12:45:25 +02:00
// Status returns tunnel status
2019-08-05 20:41:48 +02:00
func (t *tun) Status() Status {
select {
case <-t.closed:
return Closed
default:
return Connected
}
}
func (t *tun) String() string {
return "micro"
}