mercredi 5 décembre 2018

Golang get a string name of struct field

I would like to get a string name of field like it possible in C#:

if (x == null)
    throw new ArgumentNullException(nameof(x));

In GO I have the following:

package main

type Test struct{
    X int
    Y string
}

func main() {
    fmt.Println(nameof(Test.X))
}

How I can implement nameof func?





Aucun commentaire:

Enregistrer un commentaire