Fix inconsistent indents in GUIDE.md examples.

This commit is contained in:
John Beisley 2021-02-21 12:36:27 +00:00
parent 86667cb88e
commit e7fc2c5b62

View File

@ -41,15 +41,15 @@ type RouterClient interface {
NewLeaseDuration uint32, NewLeaseDuration uint32,
) (err error) ) (err error)
GetExternalIPAddress() ( GetExternalIPAddress() (
NewExternalIPAddress string, NewExternalIPAddress string,
err error, err error,
) )
} }
func PickRouterClient(ctx context.Context) (RouterClient, error) { func PickRouterClient(ctx context.Context) (RouterClient, error) {
tasks, _ := errgroup.WithContext(ctx) tasks, _ := errgroup.WithContext(ctx)
// Request each type of client in parallel, and return what is found. // Request each type of client in parallel, and return what is found.
var ip1Clients []*internetgateway2.WANIPConnection1 var ip1Clients []*internetgateway2.WANIPConnection1
tasks.Go(func() error { tasks.Go(func() error {
var err error var err error
@ -73,9 +73,9 @@ func PickRouterClient(ctx context.Context) (RouterClient, error) {
return nil, err return nil, err
} }
// Trivial handling for where we find exactly one device to talk to, you // Trivial handling for where we find exactly one device to talk to, you
// might want to provide more flexible handling than this if multiple // might want to provide more flexible handling than this if multiple
// devices are found. // devices are found.
switch { switch {
case len(ip2Clients) == 1: case len(ip2Clients) == 1:
return ip2Clients[0], nil return ip2Clients[0], nil
@ -94,36 +94,36 @@ external IP address and forward it to a port on your local network, e.g:
```go ```go
func GetIPAndForwardPort(ctx context.Context) error { func GetIPAndForwardPort(ctx context.Context) error {
client, err := PickRouterClient(ctx) client, err := PickRouterClient(ctx)
if err != nil { if err != nil {
return err return err
} }
externalIP, err := client.GetExternalIPAddress() externalIP, err := client.GetExternalIPAddress()
if err != nil { if err != nil {
return err return err
} }
fmt.Println("Our external IP address is: ", externalIP) fmt.Println("Our external IP address is: ", externalIP)
return client.AddPortMapping( return client.AddPortMapping(
"", "",
// External port number to expose to Internet: // External port number to expose to Internet:
1234, 1234,
// Forward TCP (this could be "UDP" if we wanted that instead). // Forward TCP (this could be "UDP" if we wanted that instead).
"TCP", "TCP",
// Internal port number on the LAN to forward to. // Internal port number on the LAN to forward to.
// Some routers might not support this being different to the external // Some routers might not support this being different to the external
// port number. // port number.
1234, 1234,
// Internal address on the LAN we want to forward to. // Internal address on the LAN we want to forward to.
"192.168.1.6", "192.168.1.6",
// Enabled: // Enabled:
true, true,
// Informational description for the client requesting the port forwarding. // Informational description for the client requesting the port forwarding.
"MyProgramName", "MyProgramName",
// How long should the port forward last for in seconds. // How long should the port forward last for in seconds.
// If you want to keep it open for longer and potentially across router // If you want to keep it open for longer and potentially across router
// resets, you might want to periodically request before this elapses. // resets, you might want to periodically request before this elapses.
3600, 3600,
) )
} }