Skip to content

Commit f168bda

Browse files
committed
chore: remove unused code
1 parent 925548b commit f168bda

File tree

2 files changed

+7
-46
lines changed

2 files changed

+7
-46
lines changed

api/data_to_point.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import (
2626
// Description string `lp:"-"`
2727
// }
2828
func DataToPoint(x interface{}) (*write.Point, error) {
29-
if err := checkContainerType(x, false, "point"); err != nil {
30-
return nil, err
31-
}
3229
t := reflect.TypeOf(x)
3330
v := reflect.ValueOf(x)
3431
if t.Kind() == reflect.Ptr {
3532
t = t.Elem()
3633
v = v.Elem()
3734
}
35+
if t.Kind() != reflect.Struct {
36+
return nil, fmt.Errorf("cannot use %v as point", t)
37+
}
3838
fields := reflect.VisibleFields(t)
3939

4040
var measurement = ""
@@ -56,6 +56,10 @@ func DataToPoint(x interface{}) (*write.Point, error) {
5656
if len(parts) == 2 {
5757
name = parts[1]
5858
}
59+
t := getFieldType(v.FieldByIndex(f.Index))
60+
if !validFieldType(t) {
61+
return nil, fmt.Errorf("cannot use field '%s' of type '%v' as to create a point", f.Name, t)
62+
}
5963
switch typ {
6064
case "measurement":
6165
if measurement != "" {

api/reflection.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,10 @@
11
package api
22

33
import (
4-
"fmt"
54
"reflect"
65
"time"
76
)
87

9-
// checkContainerType validates the value is struct with simple type fields
10-
// or a map with key as string and value as a simple type
11-
func checkContainerType(p interface{}, alsoMap bool, usage string) error {
12-
if p == nil {
13-
return nil
14-
}
15-
t := reflect.TypeOf(p)
16-
v := reflect.ValueOf(p)
17-
if t.Kind() == reflect.Ptr {
18-
t = t.Elem()
19-
v = v.Elem()
20-
}
21-
if t.Kind() != reflect.Struct && (!alsoMap || t.Kind() != reflect.Map) {
22-
return fmt.Errorf("cannot use %v as %s", t, usage)
23-
}
24-
switch t.Kind() {
25-
case reflect.Struct:
26-
fields := reflect.VisibleFields(t)
27-
for _, f := range fields {
28-
fv := v.FieldByIndex(f.Index)
29-
t := getFieldType(fv)
30-
if !validFieldType(t) {
31-
return fmt.Errorf("cannot use field '%s' of type '%v' as a %s", f.Name, t, usage)
32-
}
33-
34-
}
35-
case reflect.Map:
36-
key := t.Key()
37-
if key.Kind() != reflect.String {
38-
return fmt.Errorf("cannot use map key of type '%v' for %s name", key, usage)
39-
}
40-
for _, k := range v.MapKeys() {
41-
f := v.MapIndex(k)
42-
t := getFieldType(f)
43-
if !validFieldType(t) {
44-
return fmt.Errorf("cannot use map value type '%v' as a %s", t, usage)
45-
}
46-
}
47-
}
48-
return nil
49-
}
50-
518
// getFieldType extracts type of value
529
func getFieldType(v reflect.Value) reflect.Type {
5310
t := v.Type()

0 commit comments

Comments
 (0)