Skip to content

Commit

Permalink
chore: remove fileMode and use os.ModePerm
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed Sep 17, 2024
1 parent c6aca7c commit 090944b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions codegen/code_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ func (g *Generator) genModels(pkg *packages.Package, dstDir string, typeInferred
// }
// err = (&printer.Config{Mode: printer.TabIndent | printer.UseSpaces, Tabwidth: 8}).Fprint(g, fset, fileAST)

os.MkdirAll(dstDir, fileMode)
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
return err
}
fileDest := filepath.Join(dstDir, g.config.Exec.Filename)
f, err := os.OpenFile(fileDest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
f, err := os.OpenFile(fileDest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
Expand Down Expand Up @@ -615,7 +617,7 @@ func (g *Generator) genMigrations(schemas []*tableInfo) error {

func (g *Generator) genMigration(unix int64, t *tableInfo) error {
fileDest := fmt.Sprintf("%s/%d_%s.sql", g.config.Migration.Dir, unix, t.TableName())
f, err := os.OpenFile(fileDest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
f, err := os.OpenFile(fileDest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ var (
tableNameType = typeOfTable.PkgPath() + "." + typeOfTable.Name()
)

const fileMode = 0o755

const (
TagOptionAutoIncrement = "auto_increment"
TagOptionBinary = "binary"
Expand Down
2 changes: 1 addition & 1 deletion codegen/dialect/mysql/column_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *mysqlDriver) ColumnDataTypes() map[string]*dialect.ColumnType {
Scanner: "github.com/si3nloong/sqlgen/sequel/types.Float({{addrOfGoPath}})",
},
"time.Time": {
DataType: s.columnDataType("TIMESTAMP", sql.RawBytes(`NOW()`)),
DataType: s.columnDataType("TIMESTAMP", sql.RawBytes("CURRENT_TIMESTAMP")),
Valuer: "time.Time({{goPath}})",
Scanner: "(*time.Time)({{addrOfGoPath}})",
},
Expand Down
8 changes: 5 additions & 3 deletions codegen/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func Init(cfg *Config) error {
f, err := os.OpenFile(DefaultConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fileMode)
f, err := os.OpenFile(DefaultConfigFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
Expand Down Expand Up @@ -94,7 +94,9 @@ func renderTemplate(
g.WriteString(blr.String())
strpool.ReleaseString(blr)

os.MkdirAll(dstDir, fileMode)
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
return err
}
fileDest := filepath.Join(dstDir, dstFilename)
// formatted, err := format.Source([]byte(w.String()))
// if err != nil {
Expand All @@ -107,7 +109,7 @@ func renderTemplate(
g.Reset()

slog.Info("Creating " + fileDest)
if err := os.WriteFile(fileDest, formatted, fileMode); err != nil {
if err := os.WriteFile(fileDest, formatted, os.ModePerm); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 090944b

Please sign in to comment.