diff --git a/.gitignore b/.gitignore index 485dee6..97219e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +dkv diff --git a/component/config/config.go b/component/config/config.go index 52087de..7394602 100644 --- a/component/config/config.go +++ b/component/config/config.go @@ -2,10 +2,13 @@ package config import ( "flag" + "fmt" "github.com/gin-gonic/gin" "github.com/spf13/viper" "log" "net/http" + "os" + "os/exec" "strings" ) @@ -14,8 +17,25 @@ var ( ) func init() { + d := flag.Bool("d", false, "run app as a daemon with -d=true") c := flag.String("conf", "config.yaml", "configure file") - flag.Parse() + if flag.Parsed() == false { + flag.Parse() + } + if *d { + args := os.Args[1:] + i := 0 + for ; i < len(args); i++ { + if args[i] == "-d=true" { + args[i] = "-d=false" + break + } + } + cmd := exec.Command(os.Args[0], args...) + cmd.Start() + fmt.Println("[PID]", cmd.Process.Pid) + os.Exit(0) + } // 配置文件设置 C = viper.New() for _, t := range []string{"yaml", "yml"} { diff --git a/dkv b/dkv deleted file mode 100755 index a17aa22..0000000 Binary files a/dkv and /dev/null differ diff --git a/main.go b/main.go index 707c14a..16c0ca2 100644 --- a/main.go +++ b/main.go @@ -11,33 +11,11 @@ import ( "dkv/component/pprof" "dkv/store" _ "dkv/store/synchronous" - "flag" "fmt" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "os" - "os/exec" ) -func init() { - d := flag.Bool("d", false, "run app as a daemon with -d=true") - flag.Parse() - if *d { - args := os.Args[1:] - i := 0 - for ; i < len(args); i++ { - if args[i] == "-d=true" { - args[i] = "-d=false" - break - } - } - cmd := exec.Command(os.Args[0], args...) - cmd.Start() - fmt.Println("[PID]", cmd.Process.Pid) - os.Exit(0) - } -} - func main() { // 启动存储引擎 defer store.S.Close()