Skip to content

Commit 5a952a6

Browse files
committed
fix: env load file patch
1 parent b1a148d commit 5a952a6

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

cmd/frpp/cmd.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/VaalaCat/frp-panel/conf"
85
"github.com/sirupsen/logrus"
96
"github.com/spf13/cobra"
@@ -26,11 +23,6 @@ func initCommand() {
2623
apiPort int
2724
apiScheme string
2825
)
29-
hostname, err := os.Hostname()
30-
if err != nil {
31-
fmt.Println(err)
32-
os.Exit(1)
33-
}
3426

3527
clientCmd = &cobra.Command{
3628
Use: "client [-s client secret] [-i client id] [-a app secret] [-r rpc host] [-c rpc port] [-p api port]",
@@ -66,8 +58,8 @@ func initCommand() {
6658
rootCmd.AddCommand(clientCmd, serverCmd, masterCmd)
6759
clientCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
6860
serverCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
69-
clientCmd.Flags().StringVarP(&clientID, "id", "i", hostname, "client id")
70-
serverCmd.Flags().StringVarP(&clientID, "id", "i", hostname, "client id")
61+
clientCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
62+
serverCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
7163
clientCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "rpc host")
7264
serverCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "rpc host")
7365
clientCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret")
@@ -109,4 +101,8 @@ func patchConfig(host, secret, clientID, clientSecret, apiScheme string, rpcPort
109101
if len(clientSecret) != 0 {
110102
conf.Get().Client.Secret = clientSecret
111103
}
104+
logrus.Infof("env config rpc host: %s, rpc port: %d, api host: %s, api port: %d, api scheme: %s",
105+
conf.Get().Master.RPCHost, conf.Get().Master.RPCPort,
106+
conf.Get().Master.APIHost, conf.Get().Master.APIPort,
107+
conf.Get().Master.APIScheme)
112108
}

cmd/frppc/cmd.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/VaalaCat/frp-panel/conf"
85
"github.com/sirupsen/logrus"
96
"github.com/spf13/cobra"
@@ -24,11 +21,6 @@ func initCommand() {
2421
apiPort int
2522
apiScheme string
2623
)
27-
hostname, err := os.Hostname()
28-
if err != nil {
29-
fmt.Println(err)
30-
os.Exit(1)
31-
}
3224

3325
clientCmd = &cobra.Command{
3426
Use: "client [-s client secret] [-i client id] [-a app secret] [-r rpc host] [-c rpc port] [-p api port]",
@@ -46,7 +38,7 @@ func initCommand() {
4638
}
4739
rootCmd.AddCommand(clientCmd)
4840
clientCmd.Flags().StringVarP(&clientSecret, "secret", "s", "", "client secret")
49-
clientCmd.Flags().StringVarP(&clientID, "id", "i", hostname, "client id")
41+
clientCmd.Flags().StringVarP(&clientID, "id", "i", "", "client id")
5042
clientCmd.Flags().StringVarP(&rpcHost, "rpc", "r", "", "rpc host")
5143
clientCmd.Flags().StringVarP(&appSecret, "app", "a", "", "app secret")
5244

@@ -83,4 +75,8 @@ func patchConfig(host, secret, clientID, clientSecret, apiScheme string, rpcPort
8375
if len(clientSecret) != 0 {
8476
conf.Get().Client.Secret = clientSecret
8577
}
78+
logrus.Infof("env config rpc host: %s, rpc port: %d, api host: %s, api port: %d, api scheme: %s",
79+
conf.Get().Master.RPCHost, conf.Get().Master.RPCPort,
80+
conf.Get().Master.APIHost, conf.Get().Master.APIPort,
81+
conf.Get().Master.APIScheme)
8682
}

conf/settings.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package conf
22

33
import (
4+
"fmt"
5+
"os"
6+
47
"github.com/ilyakaznacheev/cleanenv"
58
"github.com/joho/godotenv"
69
"github.com/sirupsen/logrus"
@@ -80,4 +83,14 @@ func (cfg *Config) Complete() {
8083
if len(cfg.Master.APIHost) == 0 {
8184
cfg.Master.APIHost = cfg.Master.RPCHost
8285
}
86+
87+
hostname, err := os.Hostname()
88+
if err != nil {
89+
fmt.Println(err)
90+
os.Exit(1)
91+
}
92+
93+
if len(cfg.Client.ID) == 0 {
94+
cfg.Client.ID = hostname
95+
}
8396
}

0 commit comments

Comments
 (0)