server icon indicating copy to clipboard operation
server copied to clipboard

Proposal: Add an Example for Custom Hook Usage

Open TheRiseOfDavid opened this issue 1 month ago • 0 comments

Hi,

I really like this project and I would love to contribute to it. I noticed there isn't an example for using custom hooks, which made it challenging for me to figure out the correct way to implement them. I believe other newcomers might face similar difficulties.

To address this, I would like to add an example demonstrating how to use custom hooks.

Could you please guide me on how to submit to update the README.md by pull request accordingly?

Thank you!

Maybe the example like hook.go

type authHook struct {
	mqtt.HookBase
}

func (h *authHook) OnConnectAuthenticate(cl *mqtt.Client, pk packets.Packet) bool {
	if cl.Properties.Username == 'david' {
              return true
        }
        return true
}

server.go

//something to build the mqtt 
_ = server.AddHook(new(authHook), nil)
//something to start the mqtt 
err := server.Serve()

TheRiseOfDavid avatar Jun 06 '24 03:06 TheRiseOfDavid