Skip to content

Commit

Permalink
Rename HttpPort to HTTPPort
Browse files Browse the repository at this point in the history
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
  • Loading branch information
rodneyosodo committed Jul 24, 2023
1 parent f6d0673 commit bd024de
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 121 deletions.
8 changes: 4 additions & 4 deletions cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const (
svcName = "bootstrap"
envPrefixDB = "MF_BOOTSTRAP_DB_"
envPrefixES = "MF_BOOTSTRAP_ES_"
envPrefixHttp = "MF_BOOTSTRAP_HTTP_"
envPrefixHTTP = "MF_BOOTSTRAP_HTTP_"
defDB = "bootstrap"
defSvcHttpPort = "9013"
defSvcHTTPPort = "9013"
)

type config struct {
Expand Down Expand Up @@ -118,8 +118,8 @@ func main() {
svc := newService(auth, db, tracer, logger, esClient, cfg)

// Create an new HTTP server
httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/cassandra-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
const (
svcName = "cassandra-reader"
envPrefixDB = "MF_CASSANDRA_"
envPrefixHttp = "MF_CASSANDRA_READER_HTTP_"
defSvcHttpPort = "9003"
envPrefixHTTP = "MF_CASSANDRA_READER_HTTP_"
defSvcHTTPPort = "9003"
)

type config struct {
Expand Down Expand Up @@ -92,8 +92,8 @@ func main() {
repo := newService(csdSession, logger)

// Create new http server
httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/cassandra-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
const (
svcName = "cassandra-writer"
envPrefixDB = "MF_CASSANDRA_"
envPrefixHttp = "MF_CASSANDRA_WRITER_HTTP_"
defSvcHttpPort = "9004"
envPrefixHTTP = "MF_CASSANDRA_WRITER_HTTP_"
defSvcHTTPPort = "9004"
)

type config struct {
Expand Down Expand Up @@ -88,8 +88,8 @@ func main() {
}()
tracer := tp.Tracer(svcName)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefix, AltPrefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/certs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
const (
svcName = "certs"
envPrefixDB = "MF_CERTS_DB_"
envPrefixHttp = "MF_CERTS_HTTP_"
envPrefixHTTP = "MF_CERTS_HTTP_"
defDB = "certs"
defSvcHttpPort = "9019"
defSvcHTTPPort = "9019"
)

type config struct {
Expand Down Expand Up @@ -119,8 +119,8 @@ func main() {

svc := newService(auth, db, tracer, logger, cfg, pkiClient)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger)
Expand Down
12 changes: 6 additions & 6 deletions cmd/coap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
const (
svcName = "coap_adapter"
envPrefix = "MF_COAP_ADAPTER_"
envPrefixHttp = "MF_COAP_ADAPTER_HTTP_"
defSvcHttpPort = "5683"
defSvcCoapPort = "5683"
envPrefixHTTP = "MF_COAP_ADAPTER_HTTP_"
defSvcHTTPPort = "5683"
defSvcCoAPPort = "5683"
)

type config struct {
Expand Down Expand Up @@ -101,13 +101,13 @@ func main() {
counter, latency := internal.MakeMetrics(svcName, "api")
svc = api.MetricsMiddleware(svc, counter, latency)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(instanceID), logger)

coapServerConfig := server.Config{Port: defSvcCoapPort}
coapServerConfig := server.Config{Port: defSvcCoAPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s CoAP server configuration : %s", svcName, err))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
const (
svcName = "http_adapter"
envPrefix = "MF_HTTP_ADAPTER_"
defSvcHttpPort = "80"
defSvcHTTPPort = "80"
)

type config struct {
Expand Down Expand Up @@ -95,7 +95,7 @@ func main() {

svc := newService(pub, tc, logger, tracer)

httpServerConfig := server.Config{Port: defSvcHttpPort}
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/influxdb-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (

const (
svcName = "influxdb-reader"
envPrefixHttp = "MF_INFLUX_READER_HTTP_"
envPrefixHTTP = "MF_INFLUX_READER_HTTP_"
envPrefixDB = "MF_INFLUXDB_"
defSvcHttpPort = "9005"
defSvcHTTPPort = "9005"
)

type config struct {
Expand Down Expand Up @@ -97,8 +97,8 @@ func main() {

repo := newService(client, repocfg, logger)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger)
Expand Down
8 changes: 4 additions & 4 deletions cmd/influxdb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

const (
svcName = "influxdb-writer"
envPrefixHttp = "MF_INFLUX_WRITER_HTTP_"
envPrefixHTTP = "MF_INFLUX_WRITER_HTTP_"
envPrefixDB = "MF_INFLUXDB_"
defSvcHttpPort = "9006"
defSvcHTTPPort = "9006"
)

type config struct {
Expand Down Expand Up @@ -101,8 +101,8 @@ func main() {
}
defer client.Close()

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/lora/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (

const (
svcName = "lora-adapter"
envPrefixHttp = "MF_LORA_ADAPTER_HTTP_"
envPrefixHTTP = "MF_LORA_ADAPTER_HTTP_"
envPrefixRouteMap = "MF_LORA_ADAPTER_ROUTE_MAP_"
envPrefixThingsES = "MF_THINGS_ES_"
defSvcHttpPort = "9017"
defSvcHTTPPort = "9017"

thingsRMPrefix = "thing"
channelsRMPrefix = "channel"
Expand Down Expand Up @@ -119,8 +119,8 @@ func main() {
go subscribeToLoRaBroker(svc, mqttConn, cfg.LoraMsgTimeout, cfg.LoraMsgTopic, logger)
go subscribeToThingsES(svc, esConn, cfg.ESConsumerName, logger)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(instanceID), logger)
Expand Down
8 changes: 4 additions & 4 deletions cmd/mongodb-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
const (
svcName = "mongodb-reader"
envPrefixDB = "MF_MONGO_"
envPrefixHttp = "MF_MONGO_READER_HTTP_"
defSvcHttpPort = "9007"
envPrefixHTTP = "MF_MONGO_READER_HTTP_"
defSvcHTTPPort = "9007"
)

type config struct {
Expand Down Expand Up @@ -84,8 +84,8 @@ func main() {
defer authHandler.Close()
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger)
Expand Down
8 changes: 4 additions & 4 deletions cmd/mongodb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
const (
svcName = "mongodb-writer"
envPrefixDB = "MF_MONGO_"
envPrefixHttp = "MF_MONGO_WRITER_HTTP_"
defSvcHttpPort = "9008"
envPrefixHTTP = "MF_MONGO_WRITER_HTTP_"
defSvcHTTPPort = "9008"
)

type config struct {
Expand Down Expand Up @@ -91,8 +91,8 @@ func main() {
logger.Fatal(fmt.Sprintf("failed to setup mongo database : %s", err))
}

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

Expand Down
38 changes: 19 additions & 19 deletions cmd/mqtt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ const (

type config struct {
LogLevel string `env:"MF_MQTT_ADAPTER_LOG_LEVEL" envDefault:"info"`
MqttPort string `env:"MF_MQTT_ADAPTER_MQTT_PORT" envDefault:"1883"`
MqttTargetHost string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_HOST" envDefault:"localhost"`
MqttTargetPort string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_PORT" envDefault:"1883"`
MqttForwarderTimeout time.Duration `env:"MF_MQTT_ADAPTER_FORWARDER_TIMEOUT" envDefault:"30s"`
MqttTargetHealthCheck string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_HEALTH_CHECK" envDefault:""`
HttpPort string `env:"MF_MQTT_ADAPTER_WS_PORT" envDefault:"8080"`
HttpTargetHost string `env:"MF_MQTT_ADAPTER_WS_TARGET_HOST" envDefault:"localhost"`
HttpTargetPort string `env:"MF_MQTT_ADAPTER_WS_TARGET_PORT" envDefault:"8080"`
HttpTargetPath string `env:"MF_MQTT_ADAPTER_WS_TARGET_PATH" envDefault:"/mqtt"`
MQTTPort string `env:"MF_MQTT_ADAPTER_MQTT_PORT" envDefault:"1883"`
MQTTTargetHost string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_HOST" envDefault:"localhost"`
MQTTTargetPort string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_PORT" envDefault:"1883"`
MQTTForwarderTimeout time.Duration `env:"MF_MQTT_ADAPTER_FORWARDER_TIMEOUT" envDefault:"30s"`
MQTTTargetHealthCheck string `env:"MF_MQTT_ADAPTER_MQTT_TARGET_HEALTH_CHECK" envDefault:""`
HTTPPort string `env:"MF_MQTT_ADAPTER_WS_PORT" envDefault:"8080"`
HTTPTargetHost string `env:"MF_MQTT_ADAPTER_WS_TARGET_HOST" envDefault:"localhost"`
HTTPTargetPort string `env:"MF_MQTT_ADAPTER_WS_TARGET_PORT" envDefault:"8080"`
HTTPTargetPath string `env:"MF_MQTT_ADAPTER_WS_TARGET_PATH" envDefault:"/mqtt"`
Instance string `env:"MF_MQTT_ADAPTER_INSTANCE" envDefault:""`
JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"`
BrokerURL string `env:"MF_BROKER_URL" envDefault:"nats://localhost:4222"`
Expand Down Expand Up @@ -81,7 +81,7 @@ func main() {
}
}

if cfg.MqttTargetHealthCheck != "" {
if cfg.MQTTTargetHealthCheck != "" {
notify := func(e error, next time.Duration) {
logger.Info(fmt.Sprintf("Broker not ready: %s, next try in %s", e.Error(), next))
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func main() {
nps = tracing.NewPubSub(tracer, nps)
defer nps.Close()

mpub, err := mqttpub.NewPublisher(fmt.Sprintf("%s:%s", cfg.MqttTargetHost, cfg.MqttTargetPort), cfg.MqttForwarderTimeout)
mpub, err := mqttpub.NewPublisher(fmt.Sprintf("%s:%s", cfg.MQTTTargetHost, cfg.MQTTTargetPort), cfg.MQTTForwarderTimeout)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to create MQTT publisher: %s", err))
}
Expand Down Expand Up @@ -152,12 +152,12 @@ func main() {
go chc.CallHome(ctx)
}

logger.Info(fmt.Sprintf("Starting MQTT proxy on port %s", cfg.MqttPort))
logger.Info(fmt.Sprintf("Starting MQTT proxy on port %s", cfg.MQTTPort))
g.Go(func() error {
return proxyMQTT(ctx, cfg, logger, h)
})

logger.Info(fmt.Sprintf("Starting MQTT over WS proxy on port %s", cfg.HttpPort))
logger.Info(fmt.Sprintf("Starting MQTT over WS proxy on port %s", cfg.HTTPPort))
g.Go(func() error {
return proxyWS(ctx, cfg, logger, h)
})
Expand All @@ -176,8 +176,8 @@ func main() {
}

func proxyMQTT(ctx context.Context, cfg config, logger mflog.Logger, handler session.Handler) error {
address := fmt.Sprintf(":%s", cfg.MqttPort)
target := fmt.Sprintf("%s:%s", cfg.MqttTargetHost, cfg.MqttTargetPort)
address := fmt.Sprintf(":%s", cfg.MQTTPort)
target := fmt.Sprintf("%s:%s", cfg.MQTTTargetHost, cfg.MQTTTargetPort)
mp := mp.New(address, target, handler, logger)

errCh := make(chan error)
Expand All @@ -195,14 +195,14 @@ func proxyMQTT(ctx context.Context, cfg config, logger mflog.Logger, handler ses
}

func proxyWS(ctx context.Context, cfg config, logger mflog.Logger, handler session.Handler) error {
target := fmt.Sprintf("%s:%s", cfg.HttpTargetHost, cfg.HttpTargetPort)
wp := ws.New(target, cfg.HttpTargetPath, "ws", handler, logger)
target := fmt.Sprintf("%s:%s", cfg.HTTPTargetHost, cfg.HTTPTargetPort)
wp := ws.New(target, cfg.HTTPTargetPath, "ws", handler, logger)
http.Handle("/mqtt", wp.Handler())

errCh := make(chan error)

go func() {
errCh <- wp.Listen(cfg.HttpPort)
errCh <- wp.Listen(cfg.HTTPPort)
}()

select {
Expand All @@ -216,7 +216,7 @@ func proxyWS(ctx context.Context, cfg config, logger mflog.Logger, handler sessi

func healthcheck(cfg config) func() error {
return func() error {
res, err := http.Get(cfg.MqttTargetHealthCheck)
res, err := http.Get(cfg.MQTTTargetHealthCheck)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/opcua/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
const (
svcName = "opc-ua-adapter"
envPrefixES = "MF_OPCUA_ADAPTER_ES_"
envPrefixHttp = "MF_OPCUA_ADAPTER_HTTP_"
envPrefixHTTP = "MF_OPCUA_ADAPTER_HTTP_"
envPrefixRouteMap = "MF_OPCUA_ADAPTER_ROUTE_MAP_"
defSvcHttpPort = "8180"
defSvcHTTPPort = "8180"

thingsRMPrefix = "thing"
channelsRMPrefix = "channel"
Expand Down Expand Up @@ -121,8 +121,8 @@ func main() {
go subscribeToStoredSubs(ctx, sub, opcConfig, logger)
go subscribeToThingsES(ctx, svc, esConn, cfg.ESConsumerName, logger)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, httpCancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger)
Expand Down
8 changes: 4 additions & 4 deletions cmd/postgres-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
const (
svcName = "postgres-reader"
envPrefixDB = "MF_POSTGRES_"
envPrefixHttp = "MF_POSTGRES_READER_HTTP_"
envPrefixHTTP = "MF_POSTGRES_READER_HTTP_"
defDB = "messages"
defSvcHttpPort = "9009"
defSvcHTTPPort = "9009"
)

type config struct {
Expand Down Expand Up @@ -91,8 +91,8 @@ func main() {

repo := newService(db, logger)

httpServerConfig := server.Config{Port: defSvcHttpPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp}); err != nil {
httpServerConfig := server.Config{Port: defSvcHTTPPort}
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, tc, auth, svcName, instanceID), logger)
Expand Down
Loading

0 comments on commit bd024de

Please sign in to comment.