I'd say, probably type-asserting to a *types.TypeName
<https://golang.org/pkg/go/types/#TypeName> and then use Exported()
<https://golang.org/pkg/go/types/#TypeName.Exported> (the code of which
also leads to ast.IsExported <https://golang.org/pkg/go/ast/#IsExported>).

Side-note: You probably shouldn't rely on parsing the output of String() of
any value, just as you shouldn't rely on parsing the output of
error.Error().

On Mon, Apr 24, 2017 at 7:06 AM, <m...@tejas.io> wrote:

> https://golang.org/pkg/go/types/#Type
>
> Is there a helper function to determine whether a *types.Type* is
> exported? It seems like I can do some string parsing like
>
> t := something.Type()
> parts := strings.Split(t.String(), ".") // go/ast.Node => ["go/ast",
> "Node"]
> ident := parts[len(parts)-1] // "Node"
> exported := strings.IsUpper(ident[0])
>
> but I imagine there's a simpler, more robust way. The end goal is to find
> out whether a type of a method argument is exported-- e.g.
> namedType := obj.Type().(*types.Named)
> method := namedType.Method(0)
> signature := method.Type().(*types.Signature)
> signature.Params().At(0).Type() // is this exported?
>
> And, for some context, all of this is from walking go/ast
>
> --
> 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.
> 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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to