Skip to content

Commit a56eca7

Browse files
connection establish loop
1 parent f25d65b commit a56eca7

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"CONNECTION_TOKEN": "memphis",
1414
"ROOT_USER": "root",
1515
"MEMPHIS_HOST":"localhost",
16-
"HTTP_PORT": "3000"
16+
"HTTP_PORT": "4444"
1717
}
1818
}
1919
]

main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import (
44
"fmt"
55
"http-proxy/conf"
66
"http-proxy/router"
7-
8-
"os"
7+
"time"
98

109
"github.com/memphisdev/memphis.go"
1110
)
@@ -14,12 +13,23 @@ var configuration = conf.GetConfig()
1413

1514
func main() {
1615
configuration := conf.GetConfig()
17-
conn, err := memphis.Connect(configuration.MEMPHIS_HOST, configuration.ROOT_USER, configuration.CONNECTION_TOKEN)
18-
if err != nil {
19-
fmt.Println(err.Error())
20-
os.Exit(1)
16+
var conn *memphis.Conn
17+
ticker := time.NewTicker(1 * time.Second)
18+
for {
19+
select {
20+
case <-ticker.C:
21+
var err error
22+
conn, err = memphis.Connect(configuration.MEMPHIS_HOST, configuration.ROOT_USER, configuration.CONNECTION_TOKEN)
23+
if err == nil {
24+
ticker.Stop()
25+
goto serverInit
26+
} else {
27+
fmt.Printf("Awaiting to establish connection with Memphis - %v", err.Error())
28+
}
29+
}
2130
}
2231

32+
serverInit:
2333
app := router.SetupRoutes(conn)
2434
app.Listen(":" + configuration.HTTP_PORT)
2535
}

0 commit comments

Comments
 (0)