别名转换

I have struct AccessToken as a part of external library and I use that library in my own. I'd like to return a value of this type but I do not see any reasons why my internal implementation should be visible from outside. Type alias looks great for this.

type AccessToken oauth.AccessToken

But I'm getting an error when trying to do next:

func Auth(key string, secret string) *AccessToken {
...
    var token oauth.AccessToken = AuthorizeToken(...)
    return AccessToken(*token)
}

Error:

cannot use AccessToken(*accessToken) (type AccessToken) as type *AccessToken in return argument

It's clear that I can just copy structures field by fiend. But is there any way to use aliases?

I don't know what error you are getting, but this expression is wrong:

func Auth(key string, secret string) *AccessToken {
...
    var token oauth.AccessToken = AuthorizeToken(...)
    return AccessToken(*token)
}

it's saying "take the pointer-value of token (which is not a pointer at all, meaning it's a syntax error), cast that as AccessToken and return it". But the function returns a pointer to AccessToken, not a value, so this is invalid.

If you are returning a pointer to your AccessToken type, the code should be more along the lines of:

func Auth(key string, secret string) *AccessToken {
...
    token := AccessToken(AuthorizeToken(...))
    return &token
}