Certmagic: Using OnEvent to react to certificates being made

Hi! I’ve been reading the documentation for certmagic - I’m new to Go and I’ve gotten the hang of most of this, but when I set an event handler like this:

certmagic.Default.OnEvent = func(event string, data interface{}) {
	fmt.Println("certmagic:", event, "--", data)

It doesn’t seem to do anything when I start managing certificates. I’m adding certificates to be managed by calling ManageSync on the certmagic.Config struct that I created with certmagic.NewDefault() after making the assignment shown above.

I’m raising this partially because when I looked in the source code I couldn’t find any references to OnEvent - has this property been deprecated?

1 Like

There’s the emit() function which is called in various places, which is what triggers the events.

I think everything looks wired up correctly. Make sure you set certmagic.Default.OnEvent before calling NewDefault(), I guess.


Ahh! Thank you for this. Understanding that it’s the calls to emit which create the events has been extremely useful.

Whilst I’ve been testing locally I haven’t actually generated any certificates - I had assumed that certain errors would also be emitted. Thanks!

1 Like

This topic was automatically closed after 60 days. New replies are no longer allowed.