I have function that creates a slice like this :
func buildOptions(cfg *ServerConfig) []SomeType {
return []SomeType{
Option1,
Option2,
Option3,
}
}
I need Option3 to be added to the slice only if a certain condition is met. Can it be done with some kind of immediate if in the same statement?
of do I have to do something like this:
func buildOptions(cfg *ServerConfig) []SomeType {
options:= []SomeType{
Option1,
Option2,
}
if addOption3==true{
options = append(options, Option3)
}
return options
}