package main

import (
	"io/ioutil"
	"os"
	"os/exec"
	"regexp"
	"strings"
)

var (
	newlinePattern = regexp.MustCompile("\r\n|\r|\n")
)

func getLocalIP() string {
	for _, i := range []string{"en0", "en1", "en2"} {
		cmd := exec.Command("ipconfig", "getifaddr", i)
		b, err := cmd.Output()
		if err != nil {
			continue
		}

		if len(b) > 0 {
			return strings.Trim(string(b[:]), "\n")
		}
	}

	return ""
}

func removeWrapperPrefix(str string) (string, bool) {
	const prefix = "dor-"
	had := strings.HasPrefix(str, prefix)
	return strings.TrimPrefix(str, prefix), had
}

func loadHelpFile(file string) (summary, description string) {
	f, err := os.Open(file)
	if err != nil {
		return
	}

	b, err := ioutil.ReadAll(f)
	if err != nil {
		return
	}

	description = string(b[:])
	summary = newlinePattern.Split(description, 2)[0]
	return
}

package main

import (
	"io/ioutil"
	"net"
	"os"
	"regexp"
	"strings"
)

var (
	newlinePattern = regexp.MustCompile("\r\n|\r|\n")
)

func getLocalIP() string {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return ""
	}

	for _, address := range addrs {
		ipnet, ok := address.(*net.IPNet)
		if !ok {
			continue
		}

		if ipnet.IP.IsLoopback() {
			continue
		}
		if ipnet.IP.To4() == nil {
			continue
		}

		return ipnet.IP.String()
	}

	return ""
}

func removeWrapperPrefix(str string) (string, bool) {
	const prefix = "dor-"
	had := strings.HasPrefix(str, prefix)
	return strings.TrimPrefix(str, prefix), had
}

func loadHelpFile(file string) (summary, description string) {
	f, err := os.Open(file)
	if err != nil {
		return
	}

	b, err := ioutil.ReadAll(f)
	if err != nil {
		return
	}

	description = string(b[:])
	summary = newlinePattern.Split(description, 2)[0]
	return
}

Fix the way to get local ip
Fix the way to get local ip
