@@ -17,18 +17,20 @@ var (
1717 //readiness probe file path (container healthcheck)
1818 LISTENER_HEALTHFILE_PATH = os .Getenv ("MQTT_CONNECT_SUCCESS_PATH" )
1919 PUB_HEALTHFILE_PATH = os .Getenv ("PUBSUB_CONNECT_SUCCESS_PATH" )
20+ MODE_PATH = os .Getenv ("MODE_PATH" )
2021)
2122
2223var (
2324 //target= verne container in same pod (hence TCP at localhost:1883)
2425 Broker string = os .Getenv ("MQTT_BROKER_ADDRESS" )
2526 Port int = 1883
26- projectID string = "gcplocal-emulator"
27+ projectID string = os . Getenv ( "PROJECT_ID" )
2728 pubsubTopic string = "source"
2829
2930 MqttTopicPath string = os .Getenv ("MQTT_TOPIC" )
3031 pubsubPort string = "8085"
3132 pubsubHost string = os .Getenv ("PUBSUB_HOST" )
33+ mode string = "dev"
3234)
3335
3436var (
@@ -60,6 +62,7 @@ func localConfigs() {
6062 //read host_ip (for k3s local) -> node where gcp emulator runs
6163 data , err := os .ReadFile ("/envs/host_ip" )
6264 if err != nil {
65+ utils .Log (utils .LOG_ERROR , "error loading host_ip from /envs/host_ip" )
6366 panic (err )
6467 }
6568 hostIP := string (utils .TrimSpace (data ))
@@ -72,8 +75,19 @@ func localConfigs() {
7275 utils .Log (utils .LOG_WARN , "currently running localhost pubsub via gcp-emulator, change in production to real gcp!" )
7376}
7477
78+ func configs () {
79+ modepath , err := os .ReadFile (MODE_PATH )
80+ if err != nil {
81+ utils .Log (utils .LOG_ERROR , utils .Sprintf ("error finding what mode to set at %s" ))
82+ }
83+ mode = string (utils .TrimSpace (modepath ))
84+ if mode == "dev" {
85+ localConfigs ()
86+ }
87+ }
88+
7589func main () {
76- localConfigs ()
90+ configs ()
7791
7892 //connect to pubsub (+channel for publishing)
7993 pubctx , pubclient = confPubSub (projectID )
@@ -151,7 +165,11 @@ func confPubSub(projectID string) (context.Context, *pubsub.Client) {
151165 if err != nil {
152166 utils .Log (utils .LOG_ERROR , utils .Sprintf ("failed to create pubsub client: %v" , err ))
153167 }
154- utils .Log (utils .LOG_DEBUG , utils .Sprintf ("connected to pubsub host: %s" , os .Getenv ("PUBSUB_EMULATOR_HOST" )))
168+ if MODE_PATH == "dev" {
169+ utils .Log (utils .LOG_DEBUG , utils .Sprintf ("connected to pubsub host: %s" , os .Getenv ("PUBSUB_EMULATOR_HOST" )))
170+ } else {
171+ utils .Log (utils .LOG_DEBUG , "connected to pubsub host" )
172+ }
155173 logSuccess (PUB_HEALTHFILE_PATH )
156174 return ctx , client
157175}
0 commit comments