0x4a52466c696e74 il y a 2 ans
Parent
commit
8202d5e2ba
1 fichiers modifiés avec 15 ajouts et 4 suppressions
  1. 15 4
      json/map.go

+ 15 - 4
json/map.go

@@ -74,12 +74,23 @@ func val(l, r interface{}) (res reflect.Value) {
 	return
 }
 
+func isType(l, r any) bool {
+	rType := reflect.ValueOf(r).Type()
+	lType := reflect.ValueOf(l).Type()
+	//log.Println(rType, lType, reflect.ValueOf(iface).Convert(rType))
+	return lType.ConvertibleTo(rType)
+}
+
 func (s Map) IsInt(key string) bool {
 	if iface, check := s[key]; check {
-		rType := reflect.ValueOf(int(0)).Type()
-		lType := reflect.ValueOf(iface).Type()
-		//log.Println(rType, lType, reflect.ValueOf(iface).Convert(rType))
-		return lType.ConvertibleTo(rType)
+		return isType(iface, int(0))
+	}
+	return false
+}
+
+func (s Map) IsBoolean(key string) bool {
+	if iface, check := s[key]; check {
+		return isType(iface, false)
 	}
 	return false
 }