Skip to content

Commit

Permalink
Removing port from ping-pong-mesh client (#10)
Browse files Browse the repository at this point in the history
* Adding relevant Istio config to mesh workloads

* Removes port from client call in ping-pong-mesh

* Remove str formatter for lint

* [lint] removing unused function
  • Loading branch information
jsnctl authored Dec 19, 2024
1 parent e9f1b48 commit fae96c5
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions workloads/ping-pong-mesh/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"time"
)

Expand All @@ -20,8 +19,7 @@ func main() {
}

type Env struct {
ServerAddress string
ServerPort int
ServerAddress string
}

func getEnvOrPanic(variable string) string {
Expand All @@ -32,24 +30,9 @@ func getEnvOrPanic(variable string) string {
return v
}

func getEnvIntWithDefault(variable string, defaultValue int) int {
v, ok := os.LookupEnv(variable)
if !ok {
return defaultValue
}

intValue, err := strconv.Atoi(v)
if err != nil {
return defaultValue
}

return intValue
}

func getEnv() *Env {
return &Env{
ServerAddress: getEnvOrPanic("PING_PONG_SERVICE_HOST"),
ServerPort: getEnvIntWithDefault("PING_PONG_SERVICE_PORT", 80),
ServerAddress: getEnvOrPanic("PING_PONG_SERVICE_HOST"),
}
}

Expand All @@ -60,17 +43,17 @@ func run(ctx context.Context, env *Env) error {

for {
slog.Info("ping...")
if err := ping(client, env.ServerAddress, env.ServerPort); err != nil {
if err := ping(client, env.ServerAddress); err != nil {
slog.Error("problem reaching server", "error", err)
}
time.Sleep(5 * time.Second)
}
}

func ping(client *http.Client, serverAddr string, serverPort int) error {
func ping(client *http.Client, serverAddr string) error {
r, err := client.Get((&url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s:%d", serverAddr, serverPort),
Host: serverAddr,
}).String())

if err != nil {
Expand Down

0 comments on commit fae96c5

Please sign in to comment.