--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Hi Kiki,
Thanks for explaining.
But it’s better to pass the error upstream and re-invoke the handler after repairing the connection, since failover is supposed to be a rare edge case.
Can you explain a little about what you’re suggesting I should do? “db” is created in main and then it’s passed to HTTP handlers as arguments in my case.
db, err := getDB()
and then later in code:-
// Start web server.
http.HandleFunc("/tokens", func(w http.ResponseWriter, r *http.Request) {
tokensHandler(w, r, db, *envPtr)
})
http.HandleFunc("/add", func(w http.ResponseWriter, r *http.Request) {
agentsHandler(w, r, db, *envPtr)
Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Hi Kiki,
I still have doubts. Sorry about that.
db = validDb // some failover magic here
This operation is not atomic. Hence, while this is happening, other http handlers will also fail. I verified that by adding a time.Sleep in the example code. How can I avoid that?
Is putting mutexes around all access to db object the only way, for both reads and writes? I feel that it’s ugly and that’s why I’m looking for a better solution.
Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.