1
1
package run
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
6
+ "encoding/json"
7
+ "fmt"
5
8
"grm/common"
9
+ "grm/global"
6
10
"grm/router"
7
11
"grm/web"
8
12
"io/ioutil"
@@ -11,6 +15,7 @@ import (
11
15
"net/http"
12
16
"os"
13
17
"os/signal"
18
+ "strings"
14
19
"time"
15
20
16
21
"github.com/gin-gonic/gin"
@@ -24,17 +29,43 @@ var CmdRun = &cobra.Command{
24
29
}
25
30
26
31
var (
27
- host string
28
- port string
32
+ host string
33
+ port string
34
+ confirm string
29
35
)
30
36
31
37
func 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" )
34
41
}
35
42
36
43
func runFunction (cmd * cobra.Command , args []string ) {
37
44
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
+
38
69
gin .SetMode (gin .ReleaseMode )
39
70
gin .DefaultWriter = ioutil .Discard
40
71
0 commit comments