From bd024de89d38bc66742c37429202e52098b376f9 Mon Sep 17 00:00:00 2001 From: rodneyosodo Date: Mon, 24 Jul 2023 10:40:17 +0300 Subject: [PATCH] Rename HttpPort to HTTPPort Signed-off-by: rodneyosodo --- cmd/bootstrap/main.go | 8 ++++---- cmd/cassandra-reader/main.go | 8 ++++---- cmd/cassandra-writer/main.go | 8 ++++---- cmd/certs/main.go | 8 ++++---- cmd/coap/main.go | 12 ++++++------ cmd/http/main.go | 4 ++-- cmd/influxdb-reader/main.go | 8 ++++---- cmd/influxdb-writer/main.go | 8 ++++---- cmd/lora/main.go | 8 ++++---- cmd/mongodb-reader/main.go | 8 ++++---- cmd/mongodb-writer/main.go | 8 ++++---- cmd/mqtt/main.go | 38 ++++++++++++++++++------------------ cmd/opcua/main.go | 8 ++++---- cmd/postgres-reader/main.go | 8 ++++---- cmd/postgres-writer/main.go | 8 ++++---- cmd/smpp-notifier/main.go | 8 ++++---- cmd/smtp-notifier/main.go | 8 ++++---- cmd/things/main.go | 12 ++++++------ cmd/timescale-reader/main.go | 8 ++++---- cmd/timescale-writer/main.go | 8 ++++---- cmd/twins/main.go | 8 ++++---- cmd/users/main.go | 12 ++++++------ cmd/ws/main.go | 8 ++++---- internal/env/load.go | 10 ---------- 24 files changed, 111 insertions(+), 121 deletions(-) delete mode 100644 internal/env/load.go diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 88c2663c200..0590de0baab 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -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 { @@ -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)) } diff --git a/cmd/cassandra-reader/main.go b/cmd/cassandra-reader/main.go index d1b84525429..343a443f89d 100644 --- a/cmd/cassandra-reader/main.go +++ b/cmd/cassandra-reader/main.go @@ -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 { @@ -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)) } diff --git a/cmd/cassandra-writer/main.go b/cmd/cassandra-writer/main.go index e322920553c..0c7a5d5988f 100644 --- a/cmd/cassandra-writer/main.go +++ b/cmd/cassandra-writer/main.go @@ -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 { @@ -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)) } diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 1709203fe12..11c70a3b2c3 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -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 { @@ -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) diff --git a/cmd/coap/main.go b/cmd/coap/main.go index d4b58c3cc28..78b16c52cda 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -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 { @@ -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)) } diff --git a/cmd/http/main.go b/cmd/http/main.go index ecf1be6bd31..4f4f1e4880c 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -35,7 +35,7 @@ import ( const ( svcName = "http_adapter" envPrefix = "MF_HTTP_ADAPTER_" - defSvcHttpPort = "80" + defSvcHTTPPort = "80" ) type config struct { @@ -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)) } diff --git a/cmd/influxdb-reader/main.go b/cmd/influxdb-reader/main.go index 905e2d4b8c4..84e762dfc2b 100644 --- a/cmd/influxdb-reader/main.go +++ b/cmd/influxdb-reader/main.go @@ -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 { @@ -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) diff --git a/cmd/influxdb-writer/main.go b/cmd/influxdb-writer/main.go index 8025f6d2d31..fab4d7ed3a1 100644 --- a/cmd/influxdb-writer/main.go +++ b/cmd/influxdb-writer/main.go @@ -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 { @@ -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)) } diff --git a/cmd/lora/main.go b/cmd/lora/main.go index c33727f5177..1126ec662a3 100644 --- a/cmd/lora/main.go +++ b/cmd/lora/main.go @@ -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" @@ -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) diff --git a/cmd/mongodb-reader/main.go b/cmd/mongodb-reader/main.go index 91b3c0cb37b..b6453140b54 100644 --- a/cmd/mongodb-reader/main.go +++ b/cmd/mongodb-reader/main.go @@ -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 { @@ -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) diff --git a/cmd/mongodb-writer/main.go b/cmd/mongodb-writer/main.go index be8772721f4..2baa72a2d28 100644 --- a/cmd/mongodb-writer/main.go +++ b/cmd/mongodb-writer/main.go @@ -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 { @@ -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)) } diff --git a/cmd/mqtt/main.go b/cmd/mqtt/main.go index d07507aff49..5e134873a7a 100644 --- a/cmd/mqtt/main.go +++ b/cmd/mqtt/main.go @@ -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"` @@ -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)) } @@ -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)) } @@ -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) }) @@ -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) @@ -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 { @@ -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 } diff --git a/cmd/opcua/main.go b/cmd/opcua/main.go index 423738ef565..3539a54c461 100644 --- a/cmd/opcua/main.go +++ b/cmd/opcua/main.go @@ -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" @@ -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) diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index ad3657cbef6..4579f1514b7 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -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 { @@ -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) diff --git a/cmd/postgres-writer/main.go b/cmd/postgres-writer/main.go index 5eac8c06583..0d7928828d9 100644 --- a/cmd/postgres-writer/main.go +++ b/cmd/postgres-writer/main.go @@ -33,9 +33,9 @@ import ( const ( svcName = "postgres-writer" envPrefixDB = "MF_POSTGRES_" - envPrefixHttp = "MF_POSTGRES_WRITER_HTTP_" + envPrefixHTTP = "MF_POSTGRES_WRITER_HTTP_" defDB = "messages" - defSvcHttpPort = "9010" + defSvcHTTPPort = "9010" ) type config struct { @@ -94,8 +94,8 @@ func main() { } defer db.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)) } diff --git a/cmd/smpp-notifier/main.go b/cmd/smpp-notifier/main.go index c0b0e152504..bd2525916f4 100644 --- a/cmd/smpp-notifier/main.go +++ b/cmd/smpp-notifier/main.go @@ -40,9 +40,9 @@ import ( const ( svcName = "smpp-notifier" envPrefixDB = "MF_SMPP_NOTIFIER_DB_" - envPrefixHttp = "MF_SMPP_NOTIFIER_HTTP_" + envPrefixHTTP = "MF_SMPP_NOTIFIER_HTTP_" defDB = "subscriptions" - defSvcHttpPort = "9014" + defSvcHTTPPort = "9014" ) type config struct { @@ -119,8 +119,8 @@ func main() { logger.Fatal(fmt.Sprintf("failed to create Postgres writer: %s", err)) } - 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) diff --git a/cmd/smtp-notifier/main.go b/cmd/smtp-notifier/main.go index 0fb63ff72be..40dffdcfd63 100644 --- a/cmd/smtp-notifier/main.go +++ b/cmd/smtp-notifier/main.go @@ -41,9 +41,9 @@ import ( const ( svcName = "smtp-notifier" envPrefixDB = "MF_SMTP_NOTIFIER_DB_" - envPrefixHttp = "MF_SMTP_NOTIFIER_HTTP_" + envPrefixHTTP = "MF_SMTP_NOTIFIER_HTTP_" defDB = "subscriptions" - defSvcHttpPort = "9015" + defSvcHTTPPort = "9015" ) type config struct { @@ -121,8 +121,8 @@ func main() { logger.Fatal(fmt.Sprintf("failed to create Postgres writer: %s", err)) } - 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) diff --git a/cmd/things/main.go b/cmd/things/main.go index a592d9986cd..e6a5ddaeb4f 100644 --- a/cmd/things/main.go +++ b/cmd/things/main.go @@ -59,11 +59,11 @@ const ( envPrefixDB = "MF_THINGS_DB_" envPrefixCache = "MF_THINGS_CACHE_" envPrefixES = "MF_THINGS_ES_" - envPrefixHttp = "MF_THINGS_HTTP_" + envPrefixHTTP = "MF_THINGS_HTTP_" envPrefixGRPC = "MF_THINGS_GRPC_" defDB = "things" - defSvcHttpPort = "9000" - defSvcAuthGrpcPort = "7000" + defSvcHTTPPort = "9000" + defSvcAuthGRPCPort = "7000" ) type config struct { @@ -149,8 +149,8 @@ func main() { csvc, gsvc, psvc := newService(db, auth, cacheClient, esClient, cfg.CacheKeyDuration, tracer, 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 gRPC server configuration : %s", svcName, err)) } mux := bone.New() @@ -162,7 +162,7 @@ func main() { reflection.Register(srv) tpolicies.RegisterThingsServiceServer(srv, grpcapi.NewServer(csvc, psvc)) } - grpcServerConfig := server.Config{Port: defSvcAuthGrpcPort} + grpcServerConfig := server.Config{Port: defSvcAuthGRPCPort} if err := env.Parse(&grpcServerConfig, env.Options{Prefix: envPrefixGRPC}); err != nil { logger.Fatal(fmt.Sprintf("failed to load %s gRPC server configuration : %s", svcName, err)) } diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index 518af4c3a85..4d8bd2b765b 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -31,9 +31,9 @@ import ( const ( svcName = "timescaledb-reader" envPrefixDB = "MF_TIMESCALE_" - envPrefixHttp = "MF_TIMESCALE_READER_HTTP_" + envPrefixHTTP = "MF_TIMESCALE_READER_HTTP_" defDB = "messages" - defSvcHttpPort = "9011" + defSvcHTTPPort = "9011" ) type config struct { @@ -90,8 +90,8 @@ func main() { defer tcHandler.Close() logger.Info("Successfully connected to things grpc server " + tcHandler.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) diff --git a/cmd/timescale-writer/main.go b/cmd/timescale-writer/main.go index 78351b05094..40fdef6cb85 100644 --- a/cmd/timescale-writer/main.go +++ b/cmd/timescale-writer/main.go @@ -34,9 +34,9 @@ import ( const ( svcName = "timescaledb-writer" envPrefixDB = "MF_TIMESCALE_" - envPrefixHttp = "MF_TIMESCALE_WRITER_HTTP_" + envPrefixHTTP = "MF_TIMESCALE_WRITER_HTTP_" defDB = "messages" - defSvcHttpPort = "9012" + defSvcHTTPPort = "9012" ) type config struct { @@ -88,8 +88,8 @@ func main() { }() tracer := tp.Tracer(svcName) - 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)) } diff --git a/cmd/twins/main.go b/cmd/twins/main.go index d276d5634ad..438a60ef248 100644 --- a/cmd/twins/main.go +++ b/cmd/twins/main.go @@ -43,10 +43,10 @@ const ( svcName = "twins" queue = "twins" envPrefixDB = "MF_TWINS_DB_" - envPrefixHttp = "MF_TWINS_HTTP_" + envPrefixHTTP = "MF_TWINS_HTTP_" envPrefixCache = "MF_TWINS_CACHE_" envPrefixES = "MF_TWINS_ES_" - defSvcHttpPort = "9018" + defSvcHTTPPort = "9018" ) type config struct { @@ -134,8 +134,8 @@ func main() { svc := newService(ctx, svcName, pubSub, cfg.ChannelID, auth, tracer, db, cacheClient, esClient, 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, twapi.MakeHandler(svc, logger, instanceID), logger) diff --git a/cmd/users/main.go b/cmd/users/main.go index 7466f71e19a..6098a4b7c31 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -55,11 +55,11 @@ import ( const ( svcName = "users" envPrefixDB = "MF_USERS_DB_" - envPrefixHttp = "MF_USERS_HTTP_" + envPrefixHTTP = "MF_USERS_HTTP_" envPrefixGrpc = "MF_USERS_GRPC_" defDB = "users" - defSvcHttpPort = "9002" - defSvcGrpcPort = "9192" + defSvcHTTPPort = "9002" + defSvcGRPCPort = "9192" ) type config struct { @@ -129,8 +129,8 @@ func main() { csvc, gsvc, psvc := newService(ctx, db, tracer, cfg, ec, 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.Error())) } mux := bone.New() @@ -143,7 +143,7 @@ func main() { policies.RegisterAuthServiceServer(srv, grpcapi.NewServer(csvc, psvc)) } - grpcServerConfig := server.Config{Port: defSvcGrpcPort} + grpcServerConfig := server.Config{Port: defSvcGRPCPort} if err := env.Parse(&grpcServerConfig, env.Options{Prefix: envPrefixGrpc}); err != nil { log.Fatalf("failed to load %s gRPC server configuration : %s", svcName, err.Error()) } diff --git a/cmd/ws/main.go b/cmd/ws/main.go index b86d19bd8c9..bffcf480566 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -34,8 +34,8 @@ import ( const ( svcName = "ws-adapter" - envPrefixHttp = "MF_WS_ADAPTER_HTTP_" - defSvcHttpPort = "8190" + envPrefixHTTP = "MF_WS_ADAPTER_HTTP_" + defSvcHTTPPort = "8190" ) type config struct { @@ -95,8 +95,8 @@ func main() { svc := newService(tc, nps, logger, tracer) - 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) diff --git a/internal/env/load.go b/internal/env/load.go deleted file mode 100644 index 1484af9a3c5..00000000000 --- a/internal/env/load.go +++ /dev/null @@ -1,10 +0,0 @@ -package env - -// NewConfig gets configuration from environment variable. -func NewConfig[T any](opts ...Options) (T, error) { - var cfg T - if err := Parse(&cfg, opts...); err != nil { - return cfg, err - } - return cfg, nil -}