Skip to content

Commit 9ecb2d9

Browse files
authored
Merge pull request #28 from Shelnutt2/25-open-failed
Write file if target is not empty string. Closes #25
2 parents 7a028e8 + 69fa0cc commit 9ecb2d9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: db2struct/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var structName = goopt.String([]string{"--struct"}, "", "name to set for struct"
2525
var jsonAnnotation = goopt.Flag([]string{"--json"}, []string{"--no-json"}, "Add json annotations (default)", "Disable json annotations")
2626
var gormAnnotation = goopt.Flag([]string{"--gorm"}, []string{}, "Add gorm annotations (tags)", "")
2727
var gureguTypes = goopt.Flag([]string{"--guregu"}, []string{}, "Add guregu null types", "")
28-
var targetDirectory = goopt.String([]string{"--target"}, "", "Save file path")
28+
var targetFile = goopt.String([]string{"--target"}, "", "Save file path")
2929

3030
func init() {
3131
goopt.OptArg([]string{"-p", "--password"}, "", "Mysql password", getMariadbPassword)
@@ -106,8 +106,8 @@ func main() {
106106
fmt.Println("Error in creating struct from json: " + err.Error())
107107
return
108108
}
109-
if targetDirectory != nil {
110-
file, err := os.OpenFile(*targetDirectory, os.O_WRONLY|os.O_CREATE, os.ModeAppend)
109+
if targetFile != nil && *targetFile != "" {
110+
file, err := os.OpenFile(*targetFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
111111
if err != nil {
112112
fmt.Println("Open File fail: " + err.Error())
113113
return

0 commit comments

Comments
 (0)