I Spy Code - GO

Port for network and service

Question:

This do you get get that a network service run in using go lang?

Answer:

LookupPort looks up the port for the given network and service.

Here is a go lang example that shows how get a port for a network service.

Source: (example.go)

package main
 
import (
   "net"
   "fmt"
)
 
func main() {
   port,err := net.LookupPort("tcp","ftp")
   if err == nil {
   fmt.Println("ftp port: ", port)
   }
}
 

Output:

$ go run example.go
ftp port:  21

References:

https://golang.org/pkg/net/#LookupPort