From f74948ee0ec1ef08142d05a766a70713347d6e3b Mon Sep 17 00:00:00 2001 From: "jaehoon.hyun" Date: Wed, 24 Apr 2019 16:09:25 +0900 Subject: [PATCH] add errormsg Change-Id: I1f86553b843472fa19a9e4d1b83105ef4df5a728 Signed-off-by: jaehoon.hyun --- src/errormsg/errormsg.go | 45 +++++++++++++++++++++++++++++++++++++++++++ src/errormsg/errormsg_test.go | 11 +++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/errormsg/errormsg.go create mode 100644 src/errormsg/errormsg_test.go diff --git a/src/errormsg/errormsg.go b/src/errormsg/errormsg.go new file mode 100644 index 0000000..832c898 --- /dev/null +++ b/src/errormsg/errormsg.go @@ -0,0 +1,45 @@ +package errormsg + +import ( + "errors" + "strconv" +) + +type OrchestrationError int + +const ( + ErrorNotReadyOrchestrationInit = ((1 + iota) ^ -1) + 1 + ErrorTurnOffWifi + ErrorDisconnectWifi +) + +var orchestrationErrorString = [...]string{ + "", + "ErrorNotReadyOrchestrationInit : \" Please wait until Orchestration init function has been completed \" ", + "ErrorTurnOffWifi : \" Please Turn On Wifi \" ", + "ErrorDisconnectWifi : \" Please Connect Wifi \" ", +} + +func ToString(args interface{}) string { + + switch args.(type) { + case int: + v := args.(int) + return orchestrationErrorString[v*-1] + case error: + err := args.(error) + v, _ := strconv.Atoi(err.Error()) + return orchestrationErrorString[v*-1] + } + + return "NOT SUPPORT TYPE" +} + +func ToError(orcheError int) error { + return errors.New(strconv.Itoa(orcheError)) +} + +func ToInt(err error) int { + v, _ := strconv.Atoi(err.Error()) + return v +} diff --git a/src/errormsg/errormsg_test.go b/src/errormsg/errormsg_test.go new file mode 100644 index 0000000..e35ff55 --- /dev/null +++ b/src/errormsg/errormsg_test.go @@ -0,0 +1,11 @@ +package errormsg + +import +( + "testing" +) + +func TestErrorMsg(t *testing.T) { + err := ToError(ErrorNotReadyOrchestrationInit) + t.Log(ToString(err)) +} \ No newline at end of file -- 2.7.4