Early return

This commit is contained in:
Tamir Duberstein 2015-05-11 15:47:48 -04:00
parent 6b468a429a
commit dada32c78b
6 changed files with 48 additions and 42 deletions

View File

@ -39,14 +39,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil

View File

@ -288,14 +288,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil

View File

@ -298,14 +298,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil

15
testdata/out/debug.go vendored
View File

@ -239,14 +239,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil

View File

@ -256,14 +256,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil

View File

@ -278,14 +278,15 @@ func RestoreAsset(dir, name string) error {
// RestoreAssets restores an asset under the given directory recursively // RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error { func RestoreAssets(dir, name string) error {
children, err := AssetDir(name) children, err := AssetDir(name)
if err != nil { // File // File
if err != nil {
return RestoreAsset(dir, name) return RestoreAsset(dir, name)
} else { // Dir }
for _, child := range children { // Dir
err = RestoreAssets(dir, path.Join(name, child)) for _, child := range children {
if err != nil { err = RestoreAssets(dir, path.Join(name, child))
return err if err != nil {
} return err
} }
} }
return nil return nil