Skip to content

Commit

Permalink
Change naming from host to address
Browse files Browse the repository at this point in the history
Signed-off-by: Thore Kruess <thore@kruess.xyz>
  • Loading branch information
ThoreKr committed Sep 27, 2019
1 parent 9e413d8 commit 2a4aedf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (

// Config for a Server
type Config struct {
MetricsNamespace string `yaml:"-"`
HTTPListenHost string `yaml:"http_listen_host"`
HTTPListenPort int `yaml:"http_listen_port"`
GRPCListenHost string `yaml:"grpc_listen_host"`
GRPCListenPort int `yaml:"grpc_listen_port"`
MetricsNamespace string `yaml:"-"`
HTTPListenAddress string `yaml:"http_listen_host"`
HTTPListenPort int `yaml:"http_listen_port"`
GRPCListenAddress string `yaml:"grpc_listen_host"`
GRPCListenPort int `yaml:"grpc_listen_port"`

RegisterInstrumentation bool `yaml:"register_instrumentation"`
ExcludeRequestInLog bool `yaml:"-"`
Expand All @@ -58,9 +58,9 @@ type Config struct {

// RegisterFlags adds the flags required to config this to the given FlagSet
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cfg.HTTPListenHost, "server.http-listen-host", "", "HTTP server listen host.")
f.StringVar(&cfg.HTTPListenAddress, "server.http-listen-host", "", "HTTP server listen address.")
f.IntVar(&cfg.HTTPListenPort, "server.http-listen-port", 80, "HTTP server listen port.")
f.StringVar(&cfg.GRPCListenHost, "server.grpc-listen-host", "", "gRPC server listen host.")
f.StringVar(&cfg.GRPCListenAddress, "server.grpc-listen-host", "", "gRPC server listen address.")
f.IntVar(&cfg.GRPCListenPort, "server.grpc-listen-port", 9095, "gRPC server listen port.")
f.BoolVar(&cfg.RegisterInstrumentation, "server.register-instrumentation", true, "Register the intrumentation handlers (/metrics etc).")
f.DurationVar(&cfg.ServerGracefulShutdownTimeout, "server.graceful-shutdown-timeout", 30*time.Second, "Timeout for graceful shutdowns")
Expand Down Expand Up @@ -92,12 +92,12 @@ type Server struct {
// New makes a new Server
func New(cfg Config) (*Server, error) {
// Setup listeners first, so we can fail early if the port is in use.
httpListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.HTTPListenHost, cfg.HTTPListenPort))
httpListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.HTTPListenAddress, cfg.HTTPListenPort))
if err != nil {
return nil, err
}

grpcListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.GRPCListenHost, cfg.GRPCListenPort))
grpcListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.GRPCListenAddress, cfg.GRPCListenPort))
if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (f FakeServer) Succeed(ctx context.Context, req *google_protobuf.Empty) (*g
func TestErrorInstrumentationMiddleware(t *testing.T) {
var cfg Config
cfg.RegisterFlags(flag.NewFlagSet("", flag.ExitOnError))
cfg.HTTPListenHost = "localhost"
cfg.HTTPListenAddress = "localhost"
cfg.HTTPListenPort = 9190
cfg.GRPCListenHost = "localhost"
cfg.GRPCListenAddress = "localhost"
cfg.GRPCListenPort = 1234
server, err := New(cfg)
require.NoError(t, err)
Expand Down Expand Up @@ -105,10 +105,10 @@ func TestErrorInstrumentationMiddleware(t *testing.T) {

func TestRunReturnsError(t *testing.T) {
cfg := Config{
HTTPListenHost: "localhost",
HTTPListenPort: 9190,
GRPCListenHost: "localhost",
GRPCListenPort: 9191,
HTTPListenAddress: "localhost",
HTTPListenPort: 9190,
GRPCListenAddress: "localhost",
GRPCListenPort: 9191,
}
t.Run("http", func(t *testing.T) {
cfg.MetricsNamespace = "testing_http"
Expand Down Expand Up @@ -147,12 +147,12 @@ func TestMiddlewareLogging(t *testing.T) {
var level logging.Level
level.Set("info")
cfg := Config{
HTTPListenHost: "localhost",
HTTPListenPort: 9192,
GRPCListenHost: "localhost",
HTTPMiddleware: []middleware.Interface{middleware.Logging},
MetricsNamespace: "testing_logging",
LogLevel: level,
HTTPListenAddress: "localhost",
HTTPListenPort: 9192,
GRPCListenAddress: "localhost",
HTTPMiddleware: []middleware.Interface{middleware.Logging},
MetricsNamespace: "testing_logging",
LogLevel: level,
}
server, err := New(cfg)
require.NoError(t, err)
Expand Down

0 comments on commit 2a4aedf

Please sign in to comment.