Skip to content

Commit

Permalink
none: some tiny code tidy-up (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
  • Loading branch information
Shane-XB-Qian authored Jun 1, 2024
1 parent d8364ff commit 4f62855
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cmd/datax/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func newMetricHandler(engine *datax.Engine) *metricHandler {

func (h *metricHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
if h.engine.Metrics().JSON() == nil {
j := h.engine.Metrics().JSON()
if j == nil {
return
}
w.Write([]byte(h.engine.Metrics().JSON().String()))
w.Write([]byte(j.String()))
}
7 changes: 3 additions & 4 deletions cmd/datax/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

func main() {
initLog()
var configFile = flag.String("c", "config.json", "config")
var wizardFile = flag.String("w", "", "wizard")
var httpAddr = flag.String("http", "", "http")
configFile := flag.String("c", "config.json", "config")
wizardFile := flag.String("w", "", "wizard")
httpAddr := flag.String("http", "", "http")
flag.Parse()
if *wizardFile != "" {
if err := tools.NewWizard(*configFile, *wizardFile).GenerateConfigsAndScripts(); err != nil {
Expand All @@ -46,5 +46,4 @@ func main() {
os.Exit(1)
}
fmt.Printf("run success\n")
return
}
10 changes: 6 additions & 4 deletions cmd/datax/tools/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"io/fs"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -56,7 +56,9 @@ func (w *Wizard) GenerateConfigsAndScripts() (err error) {
}

dataSourceExt := filepath.Ext(dataSourceAbsFile)
os.MkdirAll(filepath.Join(filepath.Dir(dataSourceAbsFile), "config"), 0755)
if err = os.MkdirAll(filepath.Join(filepath.Dir(dataSourceAbsFile), "config"), 0o755); err != nil {
return err
}
dataSourcePrefix := filepath.Join(filepath.Dir(dataSourceAbsFile), "config",
filepath.Base(dataSourceAbsFile)[:len(filepath.Base(dataSourceAbsFile))-len(dataSourceExt)])

Expand Down Expand Up @@ -140,14 +142,14 @@ func (w *Wizard) GenerateConfigsAndScripts() (err error) {
}

filename := dataSourcePrefix + "_" + strconv.Itoa(line) + dataSourceExt
err = ioutil.WriteFile(filename, []byte(cloneDataSource.String()), 0644)
err = os.WriteFile(filename, []byte(cloneDataSource.String()), fs.FileMode(0o644))
if err != nil {
return err
}
scripts = append(scripts, generateScript(filename))
}

err = ioutil.WriteFile("run"+ext(), []byte(strings.Join(scripts, "\n")), 0644)
err = os.WriteFile("run"+ext(), []byte(strings.Join(scripts, "\n")), fs.FileMode(0o644))
if err != nil {
return err
}
Expand Down

0 comments on commit 4f62855

Please sign in to comment.