You likely shouldn't do that in the init function, but do it from main,
where you have a clearly defined error handling path.

There are ~four things you can do with an error in init:
1. Ignore it
2. Log it
3. Store it in a package-scoped variable and check that later
4. Panic
Neither of these are good options, but they are the only ones you have.

On Wed, Mar 9, 2022 at 3:48 PM Nikhilesh Susarla <nikhilesh1...@gmail.com>
wrote:

> I have an init func in a package.
>
> Inside the init function, I have a database initialization which returns
> error. How can I handle that error failure incase if it fails in the init
> function.
>
> Thank you
> Nikhilesh
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/5600c2e2-9c6d-4a24-af98-ddf52845fe24n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/5600c2e2-9c6d-4a24-af98-ddf52845fe24n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfFbq9pCxPz-5_FyAdQL_kC%3DeE4j_87na5o9zotZy4-pTg%40mail.gmail.com.

Reply via email to