logo-MindMajix
PostGoLangGoLang
i
imran mohammad

Posted on 23rd June 2024|600 views

0
votes

Golang Struct Default Value

How can I set the default values to Golang structs?

1 answers
Answers
P
divija reddy

Posted on 23rd June 2024| 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 

}

 

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
Name
Course *
Email *
Phone Number