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

Move middlewares into handlers package #204

Merged
merged 4 commits into from Jul 25, 2017

Conversation

adamryman
Copy link
Member

@adamryman adamryman commented Jul 24, 2017

In order to configure middlewares using the NewService function in a more straight forward way, the middlewares package has been moved into handlers.

This means that the function WrapEndpoints is now in the same package as NewService, allowing the middlewares to be configured with package level variables rather than cross package variables.

This is not a complete solution, but rather an incremental improvement to the current configuration situation.

There was no real reason that middlewares became its own package, just a decision I made along the line. Both @zaquestion and @hasLeland agree that it makes sense to be part of the handlers package.

To help with the transition, running these commands in the NAME-service directory in addition to rerunning truss should result in a all old middlewares still functioning.

cat middlewares/endpoints.go | \
    sed 's|^package middlewares|package handlers|' > handlers/middlewares.go

# Note that this creates a file `service_middlewares.go` that truss will not create, 
# though this is easier than trying to combine the files together here.

cat middlewares/service.go | \
    sed 's|^package middlewares|package handlers|' > handlers/service_middlewares.go

rm middlewares/endpoints.go
rm middlewares/service.go
rmdir middlewares

Additionally:

  • rename package github.com/TuneLab/truss/gengokit/handler to github.com/TuneLab/truss/gengokit/handlers
  • add NewEndpoints to package svc/server

Copy link
Contributor

@hasLeland hasLeland left a comment

Choose a reason for hiding this comment

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

In general, a very nice little cleanup of code!

return m.prevService, nil
}
return data.ApplyTemplate(templates.ServiceBase, "Service")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I love that this logic is collapsed in the new version

@adamryman adamryman merged commit 7594080 into metaverse:master Jul 25, 2017
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.

None yet

3 participants