github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/docs/v2/design/framework/tunnel.md (about) 1 # Tunnel 2 3 The micro tunnel is a tunneling interface used to interconnect multiple networks. 4 5 ## Usage 6 7 The micro tunnel can be used as a go-micro package or as the `micro tunnel` service 8 9 ``` 10 t := tunnel.NewTunnel( 11 tunnel.Nodes(...) // list of nodes to connect to 12 ) 13 14 // connect the tunnel 15 err := t.Connect() 16 // close the tunnel 17 defer t.Close() 18 19 // listen for requests 20 l, err := t.Listen(addr) 21 22 for { 23 // accept messages 24 c, err := l.Accept() 25 // do something 26 } 27 28 // dial endpoint 29 c, err := t.Dial(addr) 30 ``` 31 32 As a service 33 34 ``` 35 # Run the tunnel server 36 micro tunnel 37 38 # connect to the tunnel specifying the server 39 micro tunnel --address=:8090 --server=:8083 40 41 # Use the tunnel as a proxy 42 MICRO_PROXY=go.micro.tunnel go run myservice.go 43 ``` 44 45 ## Protocol 46 47 The protocol is state machine as defined by the Micro-Tunnel header. 48 49 Possible message types 50 51 ``` 52 connect 53 close 54 keepalive 55 open 56 listen 57 message 58 ```