I have these 3 lines which work:
mraStr := models.MRA{}
yamlContent := loader.LoadFile("../mraProj/mra.yaml")
mraStr = Parse(yamlContent)
My question is if there is a way to write this two lines in one line in golang?
mraStr := models.MRA{}
mraStr = Parse(yamlContent)
Given the implied signatures for loader.LoadFile
(returns a single value) and Parse
(returns a models.MRA
) you can simply use a short variable declaration:
mraStr := Parse(loader.LoadFile("../mraProj/mra.yaml"))
If you want to specify the type (eg: because Parse
returns an interface), you can use the more explicit variable declaration:
var mraStr models.MRA = Parse(loader.LoadFile("../mraProj/mra.yaml"))