Skip to content

Commit

Permalink
pref: compatible with IPv6 address
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Sep 6, 2024
1 parent eaa68df commit a70b5b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/services/browser_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ func (b *browserService) createRedisClient(ctx context.Context, selConn types.Co
return
}

// get a redis client from local cache or create a new open
// if db >= 0, will also switch to db index
// get a redis client from local cache or create a new one
// if db >= 0, it will also switch to target database index
func (b *browserService) getRedisClient(server string, db int) (item *connectionItem, err error) {
b.mutex.Lock()
defer b.mutex.Unlock()
Expand Down
13 changes: 6 additions & 7 deletions backend/services/connection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"github.com/klauspost/compress/zip"
"github.com/redis/go-redis/v9"
"github.com/vrischmann/userdir"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
} else if config.Proxy.Type == 2 {
// use custom proxy
proxyUrl := url.URL{
Host: fmt.Sprintf("%s:%d", config.Proxy.Addr, config.Proxy.Port),
Host: net.JoinHostPort(config.Proxy.Addr, strconv.Itoa(config.Proxy.Port)),
}
if len(config.Proxy.Username) > 0 {
proxyUrl.User = url.UserPassword(config.Proxy.Username, config.Proxy.Password)
Expand Down Expand Up @@ -111,7 +110,7 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
return nil, errors.New("invalid login type")
}

sshAddr = fmt.Sprintf("%s:%d", config.SSH.Addr, config.SSH.Port)
sshAddr = net.JoinHostPort(config.SSH.Addr, strconv.Itoa(config.SSH.Port))
}

var tlsConfig *tls.Config
Expand Down Expand Up @@ -168,9 +167,9 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O
port = config.Port
}
if len(config.Addr) <= 0 {
option.Addr = fmt.Sprintf("127.0.0.1:%d", port)
option.Addr = net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
} else {
option.Addr = fmt.Sprintf("%s:%d", config.Addr, port)
option.Addr = net.JoinHostPort(config.Addr, strconv.Itoa(port))
}
}

Expand Down Expand Up @@ -224,7 +223,7 @@ func (c *connectionService) createRedisClient(config types.ConnectionConfig) (re
if len(addr) < 2 {
return nil, errors.New("cannot get master address")
}
option.Addr = fmt.Sprintf("%s:%s", addr[0], addr[1])
option.Addr = net.JoinHostPort(addr[0], addr[1])
option.Username = config.Sentinel.Username
option.Password = config.Sentinel.Password
}
Expand Down Expand Up @@ -310,7 +309,7 @@ func (c *connectionService) ListSentinelMasters(config types.ConnectionConfig) (
if infoMap, ok := info.(map[any]any); ok {
retInfo = append(retInfo, map[string]string{
"name": infoMap["name"].(string),
"addr": fmt.Sprintf("%s:%s", infoMap["ip"].(string), infoMap["port"].(string)),
"addr": net.JoinHostPort(infoMap["ip"].(string), infoMap["port"].(string)),
})
}
}
Expand Down

0 comments on commit a70b5b5

Please sign in to comment.