huin / goupnp

UPnP client library for Go (#golang)
BSD 2-Clause "Simplified" License
424 stars 85 forks source link

update the guide #58

Open mh-cbon opened 1 year ago

mh-cbon commented 1 year ago

at https://github.com/huin/goupnp/blob/main/GUIDE.md

we can change the example to use the LocalAddr() method :D

type RouterClient interface {
    AddPortMapping(
        NewRemoteHost string,
        NewExternalPort uint16,
        NewProtocol string,
        NewInternalPort uint16,
        NewInternalClient string,
        NewEnabled bool,
        NewPortMappingDescription string,
        NewLeaseDuration uint32,
    ) (err error)

    LocalAddr() net.IP

    GetExternalIPAddress() (
        NewExternalIPAddress string,
        err error,
    )
}

//....
    return client.AddPortMapping(
        "",
        // External port number to expose to Internet:
        1234,
        // Forward TCP (this could be "UDP" if we wanted that instead).
        "TCP",
        // Internal port number on the LAN to forward to.
        // Some routers might not support this being different to the external
        // port number.
        1234,
        // Internal address on the LAN we want to forward to.
        client.LocalAddr().String(),
        // Enabled:
        true,
        // Informational description for the client requesting the port forwarding.
        "MyProgramName",
        // How long should the port forward last for in seconds.
        // If you want to keep it open for longer and potentially across router
        // resets, you might want to periodically request before this elapses.
        3600,
    )
huin commented 1 year ago

Yes, that seems reasonable. File a PR?