-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package gopackages_test | ||
|
||
import ( | ||
"fmt" | ||
"go/format" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func tempDir(m map[string]string) (dir string, err error) { | ||
if dir, err = ioutil.TempDir("", ""); err != nil { | ||
return | ||
} | ||
for fpathrel, src := range m { | ||
if strings.HasSuffix(fpathrel, "/") { | ||
// just a dir | ||
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil { | ||
return | ||
} | ||
} else { | ||
fpath := filepath.Join(dir, fpathrel) | ||
fdir, _ := filepath.Split(fpath) | ||
if err = os.MkdirAll(fdir, 0777); err != nil { | ||
return | ||
} | ||
|
||
var formatted []byte | ||
if strings.HasSuffix(fpath, ".go") { | ||
formatted, err = format.Source([]byte(src)) | ||
if err != nil { | ||
err = fmt.Errorf("formatting %s: %v", fpathrel, err) | ||
return | ||
} | ||
} else { | ||
formatted = []byte(src) | ||
} | ||
|
||
if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package gotypes_test | ||
|
||
import ( | ||
"fmt" | ||
"go/format" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func tempDir(m map[string]string) (dir string, err error) { | ||
if dir, err = ioutil.TempDir("", ""); err != nil { | ||
return | ||
} | ||
for fpathrel, src := range m { | ||
if strings.HasSuffix(fpathrel, "/") { | ||
// just a dir | ||
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil { | ||
return | ||
} | ||
} else { | ||
fpath := filepath.Join(dir, fpathrel) | ||
fdir, _ := filepath.Split(fpath) | ||
if err = os.MkdirAll(fdir, 0777); err != nil { | ||
return | ||
} | ||
|
||
var formatted []byte | ||
if strings.HasSuffix(fpath, ".go") { | ||
formatted, err = format.Source([]byte(src)) | ||
if err != nil { | ||
err = fmt.Errorf("formatting %s: %v", fpathrel, err) | ||
return | ||
} | ||
} else { | ||
formatted = []byte(src) | ||
} | ||
|
||
if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package decorator | ||
|
||
import ( | ||
"fmt" | ||
"go/format" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func tempDir(m map[string]string) (dir string, err error) { | ||
if dir, err = ioutil.TempDir("", ""); err != nil { | ||
return | ||
} | ||
for fpathrel, src := range m { | ||
if strings.HasSuffix(fpathrel, "/") { | ||
// just a dir | ||
if err = os.MkdirAll(filepath.Join(dir, fpathrel), 0777); err != nil { | ||
return | ||
} | ||
} else { | ||
fpath := filepath.Join(dir, fpathrel) | ||
fdir, _ := filepath.Split(fpath) | ||
if err = os.MkdirAll(fdir, 0777); err != nil { | ||
return | ||
} | ||
|
||
var formatted []byte | ||
if strings.HasSuffix(fpath, ".go") { | ||
formatted, err = format.Source([]byte(src)) | ||
if err != nil { | ||
err = fmt.Errorf("formatting %s: %v", fpathrel, err) | ||
return | ||
} | ||
} else { | ||
formatted = []byte(src) | ||
} | ||
|
||
if err = ioutil.WriteFile(fpath, formatted, 0666); err != nil { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters