From 51abcb8149b3023824875eafcaad78c523264aef Mon Sep 17 00:00:00 2001 From: wuriyanto Date: Fri, 1 Nov 2024 07:19:56 +0700 Subject: [PATCH] util: move isnilish function to util package --- runner/runner.go | 5 +++-- tob.go | 21 --------------------- util/util.go | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/runner/runner.go b/runner/runner.go index 8c62826..97239c7 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -20,6 +20,7 @@ import ( "github.com/telkomdev/tob/services/postgres" "github.com/telkomdev/tob/services/redisdb" "github.com/telkomdev/tob/services/web" + "github.com/telkomdev/tob/util" ) // Runner the tob runner @@ -199,7 +200,7 @@ func healthCheck(n string, s tob.Service, t *time.Ticker, waiter tob.Waiter) { } for _, notificator := range s.GetNotificators() { - if !tob.IsNilish(notificator) { + if !util.IsNilish(notificator) { if notificator.IsEnabled() { err := notificator.Send(notificatorMessage) if err != nil { @@ -221,7 +222,7 @@ func healthCheck(n string, s tob.Service, t *time.Ticker, waiter tob.Waiter) { } for _, notificator := range s.GetNotificators() { - if !tob.IsNilish(notificator) { + if !util.IsNilish(notificator) { if notificator.IsEnabled() { err := notificator.Send(notificatorMessage) if err != nil { diff --git a/tob.go b/tob.go index 0d222f3..5921fbb 100644 --- a/tob.go +++ b/tob.go @@ -1,9 +1,5 @@ package tob -import ( - "reflect" -) - const ( // Version number @@ -15,20 +11,3 @@ const ( // NotOk service status NotOk = "NOT_OK" ) - -// IsNilish function is a function to check for nullability on the interface -func IsNilish(val any) bool { - if val == nil { - return true - } - - v := reflect.ValueOf(val) - k := v.Kind() - switch k { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, - reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return v.IsNil() - } - - return false -} diff --git a/util/util.go b/util/util.go index d3659a2..6fc15cd 100644 --- a/util/util.go +++ b/util/util.go @@ -1,6 +1,7 @@ package util import ( + "reflect" "strconv" ) @@ -56,3 +57,20 @@ func InterfaceToFloat64(val interface{}) float64 { return i } + +// IsNilish function is a function to check for nullability on the interface +func IsNilish(val any) bool { + if val == nil { + return true + } + + v := reflect.ValueOf(val) + k := v.Kind() + switch k { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, + reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return v.IsNil() + } + + return false +}