Skip to content

Commit 5b94130

Browse files
committed
feat:update
1 parent 8a453f8 commit 5b94130

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

cmd/run/root.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package run
22

33
import (
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

2631
var (
27-
host string
28-
port string
32+
host string
33+
port string
34+
confirm string
2935
)
3036

3137
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")
3441
}
3542

3643
func 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

global/default.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type GlobalConfig struct {
3737
RedisServicesCp map[string]RedisService
3838
RedisServices sync.Map
3939
Separator string
40+
Host string
41+
Port string
4042
Tree bool
4143
}
4244

@@ -51,6 +53,8 @@ var GlobalConf = GlobalConfig{
5153
Accounts: make(map[string]string),
5254
RedisServices: sync.Map{},
5355
Separator: ":",
56+
Host: "0.0.0.0",
57+
Port: "8088",
5458
Tree: true,
5559
}
5660

0 commit comments

Comments
 (0)