Skip to content

Commit 8a6babc

Browse files
all: check goimports command when boot (#7)
1 parent 84af658 commit 8a6babc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/config/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
package config
66

77
import (
8+
"bytes"
89
"flag"
910
"fmt"
1011
"io/ioutil"
1112
"os"
13+
"os/exec"
1214

1315
"github.com/gin-gonic/gin"
1416
"github.com/sirupsen/logrus"
@@ -57,9 +59,21 @@ Usage:
5759
if err != nil {
5860
logrus.Fatalf("fatal: fail to parse configuration file: %v", err)
5961
}
62+
commandCheck()
6063
gin.SetMode(conf.Mode)
6164

6265
logrus.SetFormatter(&logrus.TextFormatter{})
6366
logrus.SetReportCaller(false)
6467
logrus.Infof("load config file: %q", f)
6568
}
69+
70+
func commandCheck() {
71+
// check goimports
72+
cmd := exec.Command("goimports", "-h")
73+
cmd.Stderr = &bytes.Buffer{}
74+
err := cmd.Run()
75+
if err != nil && cmd.Stderr.(*bytes.Buffer).String() == "" {
76+
logrus.Fatalf("fatal: goimports commond not found: %v", err)
77+
return
78+
}
79+
}

0 commit comments

Comments
 (0)