You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
statping/cmd/assets.go

31 lines
723 B

package main
import (
"fmt"
"github.com/statping/statping/source"
"github.com/statping/statping/utils"
"net"
)
// UsingAssets will return true if /assets folder is present
func UsingAssets() bool {
return source.UsingAssets(utils.Directory)
}
// GetLocalIP returns the non loopback local IP of the host
func GetLocalIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "http://localhost"
}
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return fmt.Sprintf("http://%v", ipnet.IP.String())
}
}
}
return "http://localhost"
}