If at any point it is to be checked that connection is active or not, 
 `Ping` can be used as stated by Shawn.
And any operation on dirty conn should fail,  as the session is corrupt.

Though,  it seems,  auto-reconnection is already done by database/sql.
https://github.com/golang/go/issues/5718

On Wednesday, 29 November 2017 19:49:13 UTC+5:30, Nupur Bansal wrote:
>
> Hi All,
>
> I have built a Golang application based on REST services that connects to 
> different databases and fetches results.
> When 1 url is hit then if a connection does not already exist, it is 
> created. If it already exists then it is used as such. Connection is being 
> stored in a global variable that is being passed among packages.
>
> *I want to know how I will be able to check if my connection exists or not 
> in case once my db goes down and then is restarted. In that case the 
> session in my global variable will not be empty but will be broken.*
> *How to check if session variable has active connection or not ? *
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to