Posted on 22nd January 2025|600 views
How can I set the default values to Golang structs?
Posted on 22nd January 2025| views
You can write a separate constructor function.
type anything struct{
text string
Defaulttext string
}
func Newanything(text string) anything{
anything := anything{}
anything.text = text
anything.Defaulttext = “default text”
return anything
}