Skip to content

Commit

Permalink
Merge pull request #154 from jumpserver/pr@dev@wisp_port
Browse files Browse the repository at this point in the history
perf: 配置wisp port 从环境变量中提取
  • Loading branch information
feng626 authored Sep 11, 2023
2 parents a557d19 + bd26481 commit 99691d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"log"
"os"
"path/filepath"
"strings"
)

type Config struct {
Host string `mapstructure:"Host"`
Port string `mapstructure:"Port"`
WispPort string `mapstructure:"WISP_PORT"`
LogLevel string `mapstructure:"LOG_LEVEL"`
LogDirPath string
DataFolderPath string
Expand Down Expand Up @@ -40,12 +42,12 @@ func getDefaultConfig() Config {
return Config{
Host: "0.0.0.0",
Port: "8083",
WispPort: "9090",
LogLevel: "INFO",
LogDirPath: logDirPath,
DataFolderPath: dataFolderPath,
ReplayFolderPath: replayFolderPath,
}

}

func EnsureDirExist(path string) error {
Expand Down Expand Up @@ -76,7 +78,14 @@ func getPwdDirPath() string {

func loadConfigFromEnv(conf *Config) {
viper.AutomaticEnv()
if err := viper.Unmarshal(conf); err == nil {
envViper := viper.New()
for _, item := range os.Environ() {
envItem := strings.SplitN(item, "=", 2)
if len(envItem) == 2 {
envViper.Set(envItem[0], viper.Get(envItem[0]))
}
}
if err := envViper.Unmarshal(conf); err == nil {
log.Println("Load config from env")
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/httpd/grpc/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package grpc

import (
"fmt"
"github.com/jumpserver/kael/pkg/config"
"github.com/jumpserver/kael/pkg/logger"
pb "github.com/jumpserver/wisp/protobuf-go/protobuf"
"go.uber.org/zap"
Expand All @@ -17,7 +19,7 @@ type Client struct {

func (c *Client) Start() {
conn, err := grpc.Dial(
"localhost:9090",
fmt.Sprintf("localhost:%s", config.GlobalConfig.WispPort),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down

0 comments on commit 99691d2

Please sign in to comment.