I d like to, but when I write, // Load returns the list of partition found and their properties. func (l *LinuxLoader) Load() ([]*Properties, error) { //- ret := []*Properties{}
if temp, err := runDf(); err != nil { return ret, err } ret = PropertiesList(ret).Append(PropertiesList(temp)) ... # github.com/mh-cbon/disksinfo/diskinfo /tmp/go-build658543611/github.com/mh-cbon/disksinfo/diskinfo/_test/_obj_test/linux.go:25: undefined: temp FAIL github.com/mh-cbon/disksinfo/diskinfo [build failed] :X Otherwise i have to work with shadowed variable. On Thursday, March 16, 2017 at 6:59:58 PM UTC+1, Paweł Kopiczko wrote: > > Early returns are fine. You don't need all those else blocks. > > // Load returns the list of partition found and their properties. > func (l *LinuxLoader) Load() ([]*Properties, error) { > //- > ret := []*Properties{} > > if temp, err := runDf(); err != nil { > return ret, err > } > ret = PropertiesList(ret).Append(PropertiesList(temp)) > //- > if temp, err := runLsLabel(); err != nil { > return ret, err > } > ret = PropertiesList(ret).Append(PropertiesList(temp)) > //- > if temp, err := runLsUsb(); err != nil { > return ret, err > } > ret = PropertiesList(ret).Merge(PropertiesList(temp), "IsRemovable") > //- > if temp, err := runMount(); err != nil { > return ret, err > } > ret = PropertiesList(ret).Merge(PropertiesList(temp), "Label") > //- > return ret, nil > } > > On Thu, Mar 16, 2017 at 6:11 PM, <mhh...@gmail.com <javascript:>> wrote: > > Hi, > > > > golint will report > > > > if block ends with a return statement, so drop this else and outdent its > > block (move short variable declaration to its own line if necessary) > > (golint) > > > > for this code, > > > > > > // Load returns the list of partition found and their properties. > > func (l *LinuxLoader) Load() ([]*Properties, error) { > > //- > > ret := []*Properties{} > > > > if temp, err := runDf(); err != nil { > > return ret, err > > } else { > > ret = PropertiesList(ret).Append(PropertiesList(temp)) > > } > > //- > > if temp, err := runLsLabel(); err != nil { > > return ret, err > > } else { > > ret = PropertiesList(ret).Append(PropertiesList(temp)) > > } > > //- > > if temp, err := runLsUsb(); err != nil { > > return ret, err > > } else { > > ret = PropertiesList(ret).Merge(PropertiesList(temp), > "IsRemovable") > > } > > //- > > if temp, err := runMount(); err != nil { > > return ret, err > > } else { > > ret = PropertiesList(ret).Merge(PropertiesList(temp), "Label") > > } > > //- > > return ret, nil > > } > > > > Does it mean i should nest those stmts and let it be 4 level deep ? > > Is it the reco ? > > > > Is there something wrong about early returns ? > > > > thanks > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to golang-nuts...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.