Post

GoLangGoLang

i
imran mohammad

Posted on 28th March 2024|593 views

0
votes

Golang Struct Default Value

How can I set the default values to Golang structs?

Answers
P
divija reddy

Posted on 28th March 2024

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 

}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos