Skip to content

Commit

Permalink
Add for get gateway host
Browse files Browse the repository at this point in the history
  • Loading branch information
hanpengfei01 committed Aug 8, 2023
1 parent b8d4a34 commit f7e9c68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Context interface {
NewBrokerClient(mqtt.ClientConfig) (*mqtt.Client, error)
// NewSystemBrokerClient creates a new system broker client.
NewSystemBrokerClient([]mqtt.QOSTopic) (*mqtt.Client, error)
GetGatewayHost() string
}

type ctx struct {
Expand Down Expand Up @@ -334,3 +335,7 @@ func (c *ctx) NewCoreHttpClient() (*http.Client, error) {
ops.Address = getCoreInscureAdddress()
return http.NewClient(ops), nil
}

func (c *ctx) GetGatewayHost() string {
return GatewayHost()
}
3 changes: 3 additions & 0 deletions context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func TestContext_CheckSystemCert(t *testing.T) {
cc, err = ctx.NewCoreHttpsClient()
assert.NoError(t, err)
assert.NotNil(t, cc)

gateway := ctx.GetGatewayHost()
assert.Equal(t, gateway, fmt.Sprintf("%s.%s", "baetyl-gateway", baetylEdgeSystemNamespace))
}

func initCert(t *testing.T) string {
Expand Down
7 changes: 7 additions & 0 deletions context/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ func FunctionHost() string {
return fmt.Sprintf("%s.%s", "baetyl-function", baetylEdgeSystemNamespace)
}

func GatewayHost() string {
if RunMode() == RunModeNative {
return localHost
}
return fmt.Sprintf("%s.%s", "baetyl-gateway", baetylEdgeSystemNamespace)
}

func getBrokerAddress() string {
return fmt.Sprintf("%s://%s:%s", "ssl", BrokerHost(), BrokerPort())
}
Expand Down

0 comments on commit f7e9c68

Please sign in to comment.