jeudi 29 juillet 2021

check if unknown interface{} is empty

Hello I would like to know how I would be able to validate in Go if an interface{} is empty. I tried reflect.TypeOf(v) == nil, but it always returns false.

    var h  Bar
    var t  Foo
    pointers := make([]interface{}, 0)
    pointers = append(pointers, &h)
    pointers = append(pointers, &t)

func test(byteValue []byte, data []interface{}) {
    for _, v := range  data {
        fmt.Println(reflect.TypeOf(v) == nil)
        if err := lib.Unmarshal(byteValue, v); err == nil {
            fmt.Println(err)
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire