Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to idiomatic constructor pattern #10

Merged
merged 2 commits into from
Dec 31, 2023

Conversation

travbale
Copy link
Contributor

This project currently uses the following constructor pattern in several places:

type StructType struct{}

func (StructType) New() *StructType {
        return &StructType{}
}

This results in construction looking like this in packages outside the models package:

v := pkgname.StructType.New(pkgname.StructType{})

This change converts constructors to a more idomatic style.

type StructType struct{}

func NewStructType() *StructType {
        return &StructType{}
}

This results in a more straight forward construction of types.

v := pkgname.NewStructType()

@travbale travbale force-pushed the idiomatic-constructors branch from aa85306 to c36b3fa Compare December 31, 2023 18:23
@kyallanum
Copy link
Owner

@travbale I noticed that you removed the version from the go.mod as well as any import statements. What was the specific reasoning for this?

@travbale
Copy link
Contributor Author

For major versions v0/v1 you typically leave the version information off the module name. When you get to v2 you can append v2 to the end of the module name to distinguish but typically don't add minor or path version. The main reason is as currently written you would have to adjust every import path for every patch version as well. If you forget to do so you may accidentally use old package versions within the module.

@kyallanum
Copy link
Owner

For major versions v0/v1 you typically leave the version information off the module name. When you get to v2 you can append v2 to the end of the module name to distinguish but typically don't add minor or path version. The main reason is as currently written you would have to adjust every import path for every patch version as well. If you forget to do so you may accidentally use old package versions within the module.

Makes sense to me! Thanks for the help on this.

@kyallanum kyallanum merged commit d43e37f into kyallanum:main Dec 31, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants