Skip to content

Commit 51abcb8

Browse files
wuriyantowuriyanto
authored andcommitted
util: move isnilish function to util package
1 parent 02bbf59 commit 51abcb8

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

runner/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/telkomdev/tob/services/postgres"
2121
"github.com/telkomdev/tob/services/redisdb"
2222
"github.com/telkomdev/tob/services/web"
23+
"github.com/telkomdev/tob/util"
2324
)
2425

2526
// Runner the tob runner
@@ -199,7 +200,7 @@ func healthCheck(n string, s tob.Service, t *time.Ticker, waiter tob.Waiter) {
199200
}
200201

201202
for _, notificator := range s.GetNotificators() {
202-
if !tob.IsNilish(notificator) {
203+
if !util.IsNilish(notificator) {
203204
if notificator.IsEnabled() {
204205
err := notificator.Send(notificatorMessage)
205206
if err != nil {
@@ -221,7 +222,7 @@ func healthCheck(n string, s tob.Service, t *time.Ticker, waiter tob.Waiter) {
221222
}
222223

223224
for _, notificator := range s.GetNotificators() {
224-
if !tob.IsNilish(notificator) {
225+
if !util.IsNilish(notificator) {
225226
if notificator.IsEnabled() {
226227
err := notificator.Send(notificatorMessage)
227228
if err != nil {

tob.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package tob
22

3-
import (
4-
"reflect"
5-
)
6-
73
const (
84
// Version number
95

@@ -15,20 +11,3 @@ const (
1511
// NotOk service status
1612
NotOk = "NOT_OK"
1713
)
18-
19-
// IsNilish function is a function to check for nullability on the interface
20-
func IsNilish(val any) bool {
21-
if val == nil {
22-
return true
23-
}
24-
25-
v := reflect.ValueOf(val)
26-
k := v.Kind()
27-
switch k {
28-
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer,
29-
reflect.UnsafePointer, reflect.Interface, reflect.Slice:
30-
return v.IsNil()
31-
}
32-
33-
return false
34-
}

util/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package util
22

33
import (
4+
"reflect"
45
"strconv"
56
)
67

@@ -56,3 +57,20 @@ func InterfaceToFloat64(val interface{}) float64 {
5657

5758
return i
5859
}
60+
61+
// IsNilish function is a function to check for nullability on the interface
62+
func IsNilish(val any) bool {
63+
if val == nil {
64+
return true
65+
}
66+
67+
v := reflect.ValueOf(val)
68+
k := v.Kind()
69+
switch k {
70+
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer,
71+
reflect.UnsafePointer, reflect.Interface, reflect.Slice:
72+
return v.IsNil()
73+
}
74+
75+
return false
76+
}

0 commit comments

Comments
 (0)