So you have a string which contains a Go type expression, and you want to find out attributes of that type? In general you can't do that without knowing the context that the expression is to be evaluated in. For example, the string "T" could be any kind of type if T is defined as a type somewhere.
Assuming you know the package that the type expression is in, you could use https://godoc.org/golang.org/x/tools/go/packages to load it up, then use https://golang.org/pkg/go/ast to parse the type expression and use the results of the first to look up symbols from the resulting AST. cheers, rog. On Wed, 22 May 2019 at 04:14, <i...@marczahn.de> wrote: > Hi, > > for a code generator I want to get a type of a string which is passed by > an argument by go generate. So I have sth. like "[]int" and now I need to > know if it is a slice/rangeable, of type int etc. Is this somehow possible? > > I cannot have a predefined map from strings to types because it is > supposed to be generic. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/8d9ca631-8737-4c2d-99dc-bbbc37e334e7%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/8d9ca631-8737-4c2d-99dc-bbbc37e334e7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacjOXqWTPCK13FaiA%3DZAzXyv45ca9MKO4ovLpF-%2BRJZXNQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.