Skip to content

Instantly share code, notes, and snippets.

@alagalah
Created July 21, 2020 23:40
Show Gist options
  • Save alagalah/78860a8775ab00c7743f18d8cbcf5c52 to your computer and use it in GitHub Desktop.
Save alagalah/78860a8775ab00c7743f18d8cbcf5c52 to your computer and use it in GitHub Desktop.
diff --git a/examples/hotrod/cmd/customer.go b/examples/hotrod/cmd/customer.go
index ebdc5a7..9603438 100644
--- a/examples/hotrod/cmd/customer.go
+++ b/examples/hotrod/cmd/customer.go
@@ -36,7 +36,7 @@ var customerCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "customer"))
logger := log.NewFactory(zapLogger)
server := customer.NewServer(
- net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort)),
+ net.JoinHostPort(customerAddr, strconv.Itoa(customerPort)),
tracing.Init("customer", metricsFactory, logger),
metricsFactory,
logger,
diff --git a/examples/hotrod/cmd/driver.go b/examples/hotrod/cmd/driver.go
index 5e0aa2b..85b3236 100644
--- a/examples/hotrod/cmd/driver.go
+++ b/examples/hotrod/cmd/driver.go
@@ -36,7 +36,7 @@ var driverCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "driver"))
logger := log.NewFactory(zapLogger)
server := driver.NewServer(
- net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort)),
+ net.JoinHostPort(driverAddr, strconv.Itoa(driverPort)),
tracing.Init("driver", metricsFactory, logger),
metricsFactory,
logger,
diff --git a/examples/hotrod/cmd/frontend.go b/examples/hotrod/cmd/frontend.go
index 6ff6551..9b2b3be 100644
--- a/examples/hotrod/cmd/frontend.go
+++ b/examples/hotrod/cmd/frontend.go
@@ -34,10 +34,10 @@ var frontendCmd = &cobra.Command{
Long: `Starts Frontend service.`,
RunE: func(cmd *cobra.Command, args []string) error {
- options.FrontendHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(frontendPort))
- options.DriverHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort))
- options.CustomerHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort))
- options.RouteHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort))
+ options.FrontendHostPort = net.JoinHostPort(frontendAddr, strconv.Itoa(frontendPort))
+ options.DriverHostPort = net.JoinHostPort(driverAddr, strconv.Itoa(driverPort))
+ options.CustomerHostPort = net.JoinHostPort(customerAddr, strconv.Itoa(customerPort))
+ options.RouteHostPort = net.JoinHostPort(routeAddr, strconv.Itoa(routePort))
options.Basepath = basepath
zapLogger := logger.With(zap.String("service", "frontend"))
diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go
index 80342be..d88ccc6 100644
--- a/examples/hotrod/cmd/root.go
+++ b/examples/hotrod/cmd/root.go
@@ -44,6 +44,11 @@ var (
frontendPort int
routePort int
+ customerAddr string
+ driverAddr string
+ frontendAddr string
+ routeAddr string
+
basepath string
)
@@ -65,7 +70,7 @@ func Execute() {
func init() {
RootCmd.PersistentFlags().StringVarP(&metricsBackend, "metrics", "m", "expvar", "Metrics backend (expvar|prometheus)")
- RootCmd.PersistentFlags().DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "D", 300*time.Millisecond, "Average latency of MySQL DB query")
+ RootCmd.PersistentFlags().DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "S", 300*time.Millisecond, "Average latency of MySQL DB query")
RootCmd.PersistentFlags().BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection")
RootCmd.PersistentFlags().IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size")
@@ -75,6 +80,12 @@ func init() {
RootCmd.PersistentFlags().IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service")
RootCmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service")
+ // Add flags to choose addresses (IP or name) for services
+ RootCmd.PersistentFlags().StringVarP(&customerAddr, "customer-service-addr", "C", "0.0.0.0", "Addr for customer service")
+ RootCmd.PersistentFlags().StringVarP(&driverAddr, "driver-service-addr", "D", "0.0.0.0", "Addr for driver service")
+ RootCmd.PersistentFlags().StringVarP(&frontendAddr, "frontend-service-addr", "F", "0.0.0.0", "Addr for frontend service")
+ RootCmd.PersistentFlags().StringVarP(&routeAddr, "route-service-addr", "R", "0.0.0.0", "Addr for routing service")
+
// Flag for serving frontend at custom basepath url
RootCmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "", `Basepath for frontend service(default "/")`)
diff --git a/examples/hotrod/cmd/route.go b/examples/hotrod/cmd/route.go
index b962de6..d5e7919 100644
--- a/examples/hotrod/cmd/route.go
+++ b/examples/hotrod/cmd/route.go
@@ -36,7 +36,7 @@ var routeCmd = &cobra.Command{
zapLogger := logger.With(zap.String("service", "route"))
logger := log.NewFactory(zapLogger)
server := route.NewServer(
- net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)),
+ net.JoinHostPort(routeAddr, strconv.Itoa(routePort)),
tracing.Init("route", metricsFactory, logger),
logger,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment