Create a helper function that takes an Object, changes its code and returns the new Object:
func withCode(obj Obj, code string) Obj {
obj.code = code
return obj
}
Note that withCode takes a non-pointer value, so the Object you pass will not be modified, only the local copy.
And using this your task is:
var slc = []Obj{
withCode(ValidObject, "Other value"),
withCode(ValidObject, "Yet another value"),
}
fmt.Println(slc)
Output (try it on the Go Playground):
[{AK93-KADJ9-92J76 Other value MSLA-923-OKSW}
{AK93-KADJ9-92J76 Yet another value MSLA-923-OKSW}]
This helper withCode could even be a method (not a function).
Note that if you need to have variations of many fields, it would probably be better to add these as methods, so you can chain the calls.
For example:
func (o Obj) withCode(code string) Obj {
o.code = code
return o
}
func (o Obj) withSsid(ssid string) Obj {
o.ssid = ssid
return o
}
func (o Obj) withMit(mit string) Obj {
o.mit = mit
return o
}
And then using it:
var slc = []Obj{
ValidObject.withCode("code2").withSsid("ssid2"),
ValidObject.withMit("mit2").withSsid("ssid3"),
}
fmt.Println(slc)
Output (try it on the Go Playground):
[{ssid2 code2 MSLA-923-OKSW} {ssid3 SKO-120O mit2}]