jeudi 15 février 2018

Golang: Is value null (as can't use isNil for null.Time)

I am trying to make a simple function to find out if any value is null or not, as isNil() from the "reflect" package can't help with time variables.

As you can see in the code got a print for debugging which is always printing ""

func isItNull(v interface{}) bool {
    t := reflect.TypeOf(v)
    z := reflect.Zero(t)
    if v != z.Addr() {
        fmt.Println(v, z)
        return true
    }
    return false
}

Hope anybody can give me a hand or point me in the right direction.





Aucun commentaire:

Enregistrer un commentaire