DEV Community

Discussion on: How do you maintain entity state in Golang

Collapse
 
foresthoffman profile image
Forest Hoffman

Would I be correct in understanding that you want to avoid having a domainReg instance with uninitialized values? If so, yes, I believe this is a valid implementation. The vast majority of the packages that I've seen or used have some variety of your custom_subdomain.NewDomainRegistration() function. They allow you to control how things get initialized, which is not possible with plain-old struct instance construction.

Please correct me, if I'm misreading. :)

Collapse
 
purplebooth profile image
Billie

Awesome! Yeah that's exactly what I want to do.

For some reason it didn't feel very "go"

Collapse
 
foresthoffman profile image
Forest Hoffman

Sweet! I felt the same initially. It's almost like one of those "when in Rome" situations. I will say, it's quite nice when you decide you want to mock internal functions in unit tests. Then you only have to build upon the initialization function, like any other new feature, rather than having to adopt it much later.