Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Client specifies `User-Agent` HTTP header for all requests as
"toxiproxy-cli/<version> <os>/<runtime>".
Specifies client request content type as `application/json`. (#441, @miry)
* Replace Api.Listen parameters `host` and `port` with single `addr`. (#445, @miry)

# [2.5.0] - 2022-09-10

Expand Down
4 changes: 1 addition & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -51,8 +50,7 @@ func NewServer(m *metricsContainer, logger zerolog.Logger) *ApiServer {
}
}

func (server *ApiServer) Listen(host string, port string) error {
addr := net.JoinHostPort(host, port)
func (server *ApiServer) Listen(addr string) error {
server.Logger.
Info().
Str("address", addr).
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func WithServer(t *testing.T, f func(string)) {
log,
)

go testServer.Listen("localhost", "8475")
go testServer.Listen("localhost:8475")

// Allow server to start. There's no clean way to know when it listens.
time.Sleep(50 * time.Millisecond)
Expand Down
8 changes: 5 additions & 3 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"strconv"
Expand Down Expand Up @@ -89,12 +90,13 @@ func run() error {
server.PopulateConfig(cli.config)
}

go func(server *toxiproxy.ApiServer, host, port string) {
err := server.Listen(host, port)
addr := net.JoinHostPort(cli.host, cli.port)
go func(server *toxiproxy.ApiServer, addr string) {
err := server.Listen(addr)
if err != nil {
server.Logger.Err(err).Msg("Server finished with error")
}
}(server, cli.host, cli.port)
}(server, addr)

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
Expand Down