11package run
22
33import (
4+ "bytes"
45 "context"
6+ "encoding/json"
7+ "fmt"
58 "grm/common"
9+ "grm/global"
610 "grm/router"
711 "grm/web"
812 "io/ioutil"
@@ -11,6 +15,7 @@ import (
1115 "net/http"
1216 "os"
1317 "os/signal"
18+ "strings"
1419 "time"
1520
1621 "github.com/gin-gonic/gin"
@@ -24,17 +29,43 @@ var CmdRun = &cobra.Command{
2429}
2530
2631var (
27- host string
28- port string
32+ host string
33+ port string
34+ confirm string
2935)
3036
3137func init () {
32- CmdRun .Flags ().StringVarP (& host , "host" , "H" , "0.0.0.0" , "input hostname" )
33- CmdRun .Flags ().StringVarP (& port , "port" , "p" , "8088" , "input port" )
38+ confirm = "n"
39+ CmdRun .Flags ().StringVarP (& host , "host" , "H" , global .GlobalConf .Host , "input hostname" )
40+ CmdRun .Flags ().StringVarP (& port , "port" , "p" , global .GlobalConf .Port , "input port" )
3441}
3542
3643func runFunction (cmd * cobra.Command , args []string ) {
3744
45+ fmt .Printf ("%c[%d;%d;%dm%s%c[0m \n " , 0x1B , 0 , 40 , 33 , "================" , 0x1B )
46+ fmt .Printf ("%c[%d;%d;%dm Host:%s%c[0m \n " , 0x1B , 0 , 40 , 33 , host , 0x1B )
47+ fmt .Printf ("%c[%d;%d;%dm Port:%s%c[0m \n " , 0x1B , 0 , 40 , 33 , port , 0x1B )
48+ fmt .Printf ("%c[%d;%d;%dm%s%c[0m \n " , 0x1B , 0 , 40 , 33 , "================" , 0x1B )
49+ fmt .Printf ("%c[%d;%d;%dm%s%c[0m \n " , 0x1B , 0 , 40 , 33 , "Do you want to run the app at this address? Y/N" , 0x1B )
50+ fmt .Scan (& confirm )
51+
52+ if strings .ToUpper (confirm ) == "N" {
53+ os .Exit (0 )
54+ }
55+
56+ //保存host和port信息
57+ buffer := & bytes.Buffer {}
58+ encoder := json .NewEncoder (buffer )
59+ global .GlobalConf .Host = host
60+ global .GlobalConf .Port = port
61+ err := encoder .Encode (global .GlobalConf )
62+ if err != nil {
63+ fmt .Println (err )
64+ }
65+ if err = common .WriteData (buffer .Bytes ()); err != nil {
66+ fmt .Println (err )
67+ }
68+
3869 gin .SetMode (gin .ReleaseMode )
3970 gin .DefaultWriter = ioutil .Discard
4071
0 commit comments