func GetInterfaceByIndex(index int) (*net.Interface, error) {
	iface, err := net.InterfaceByIndex(index)
	if err != nil {
		return nil, errors.New("Unable to get interface by index : " + err.Error())
	}
	return iface, nil
}
Use the net library to get Interface by Index number
and capture any errors.
package main
import (
	"encoding/hex"
	"errors"
	"net"
	"strings"
)
func ExternalIP() (string, error) {
	ifaces, err := net.Interfaces()
	if err != nil {
		return "", err
	}
	for _, iface := range ifaces {
		if iface.Flags&net.FlagUp == 0 {
			continue  
		}
		if iface.Flags&net.FlagLoopback != 0 {
			continue  
		}
		addrs, err := iface.Addrs()
		if err != nil {
			return "", err
		}
		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			if ip == nil || ip.IsLoopback() {
				continue
			}
			ip = ip.To4()
			if ip == nil {
				continue  
			}
			return ip.String(), nil
		}
	}
	return "", errors.New("are you connected to the network?")
}
func GetInterfaces() []net.Interface {
	interfaces, err := net.Interfaces()
	if err != nil {
		Error.Println("Unable to get interfaces : " + err.Error())
	}
	return interfaces
}