From 90d6ba0c8fe689b177df9175e85db74b94dcfe95 Mon Sep 17 00:00:00 2001 From: "jaehoon.hyun" Date: Wed, 24 Apr 2019 15:13:38 +0900 Subject: [PATCH] common.go : enhancement error handling GetOutBoundIP occurred 2 types error - ErrorTurnOffWifi - ErrorDisconnectWifi Change-Id: I1a65704cc5c59c18ddc097b9e754ee318519c32a --- src/common/common.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/common.go b/src/common/common.go index 00c6d34..30f1683 100755 --- a/src/common/common.go +++ b/src/common/common.go @@ -17,7 +17,7 @@ package common import ( - "errors" + "errormsg" "log" "net" ) @@ -29,20 +29,25 @@ func GetOutboundIP() (addr string, err error) { if err != nil { return } + err = errormsg.ToError(errormsg.ErrorTurnOffWifi) + for _, iface := range ifaces { if iface.Name[0:2] == "wl" { + err = errormsg.ToError(errormsg.ErrorDisconnectWifi) + addrs, _ := iface.Addrs() for _, address := range addrs { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { addr = ipnet.IP.String() + err = nil return } } } } } - return "", errors.New("No interface named wl") + return "", err } func CheckError(err error) bool { -- 2.7.4