Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add an Example for Custom Hook Usage #407

Open
TheRiseOfDavid opened this issue Jun 6, 2024 · 0 comments
Open

Proposal: Add an Example for Custom Hook Usage #407

TheRiseOfDavid opened this issue Jun 6, 2024 · 0 comments

Comments

@TheRiseOfDavid
Copy link

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant