8000 NOISSUE - Decouple mainflux/mproxy and mainflux/mainflux by manuio · Pull Request #30 · absmach/mgate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NOISSUE - Decouple mainflux/mproxy and mainflux/mainflux #30

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

Merged
merged 2 commits into from
Oct 26, 2022
Merged

Conversation

manuio
Copy link
Contributor
@manuio manuio commented Sep 14, 2022

Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com

Copy link
Contributor
@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to implement a logger. It's OK to use the Mainflux logger in examples - it's a separate package anyways. So, we only need a logger interface specified. The same goes for errors - error handling in mProxy is rather simple - can we avoid having a copy of the Mainflux errors package?

@manuio
Copy link
Contributor Author
manuio commented Sep 16, 2022

@dborovcanin I'm not sure to understand. Logger is also used in the main.go. About errors package, we are using New and Wrap methods. Should we remove non used methods like Contains?

@dborovcanin
Copy link
Contributor

For logger, I meant simply defining the logger interface and taking implementation from Mainflux. In examples and in main.go, it's ok to have MF dependency because that's not something anyone will import.
For errors, I thought about completely removing that package and relying on pure Go errors because error handling is rather simple. Instead of wrap, for example, we can do something like (in session.go):

func wrap(err error, dir direction) error {
	if err == io.EOF {
		return err
	}
	switch dir {
	case up:
		return errors.New(errClient.Error() + ":" + err.Error())
	case down:
		return errors.New(errBroker.Error() + ":" + err.Error())
	default:
		return err
	}
}

…rors and logger)

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
pkg/mqtt/mqtt.go Outdated
@@ -90,7 +90,7 @@ func (p Proxy) ListenTLS(tlsCfg *tls.Config) error {

l, err := tls.Listen("tcp", p.address, tlsCfg)
if err != nil {
return errors.Wrap(errCreateListener, err)
return errors.New(errCreateListener.Error() + ":" + err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this errCreateListener, return an error directly.

switch dir {
case up:
return errors.Wrap(errClient, err)
return errors.New(errClient.Error() + ":" + err.Error())
Copy link
Contributor
@dborovcanin dborovcanin Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for errors, you can use strings constants instead like:

return errors.New(errClient + err.Error())

I quickly benchmarked errors.New(errClient + err.Error()) vs fmt.Errorf and for this simple case, it looks like simple + is the most efficient.

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Copy link
Contributor
@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@drasko drasko merged commit 5c9f19b into master Oct 26, 2022
@manuio manuio deleted the decouple branch October 26, 2022 11:05
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

Successfully merging this pull request may close these issues.

3 participants
0