Saturday, April 27, 2024
HomeGolangCasting to struct in exterior Module - Getting Assist

Casting to struct in exterior Module – Getting Assist


I’m making an attempt to forged a struct in my package deal to a different in an exterior module

In my package deal I created

sort Userinfo struct {
    username    string
    password    string
    passwordSet bool
}

which is an identical to “internet/url” Userinfo
although when I attempt to forged from one to the opposite like this:

ui := Userinfo{"myusername", "password", true}
url.Userinfo(ui)

I get

can't convert ui (variable of sort Userinfo) to sort "internet/url".Userinfo

Why can’t I forged to the opposite struct although they’re utterly an identical?
If that is typically not doable, is there some hack to take action, I have to convert to the opposite for compatibility causes?

(In fact I additionally imported “internet/url” in my package deal)

Thanks!

I believe forged must entry exported fields however on this case all fields in internet/url.Userinfo struct are personal. In accordance this, package deal internet/url presents some capabilities to create Userinfo vars like Person() and UserPassword()

HTH,
Yamil

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments