-
Notifications
You must be signed in to change notification settings - Fork 726
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
api: use middleware to get raftCluster #1908
Conversation
Signed-off-by: disksing <[email protected]>
Signed-off-by: disksing <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1908 +/- ##
==========================================
+ Coverage 77.33% 77.87% +0.53%
==========================================
Files 165 167 +2
Lines 16590 16530 -60
==========================================
+ Hits 12830 12872 +42
+ Misses 2750 2665 -85
+ Partials 1010 993 -17
Continue to review full report at Codecov.
|
server/api/router.go
Outdated
@@ -28,127 +28,130 @@ func createRouter(prefix string, svr *server.Server) *mux.Router { | |||
IndentJSON: true, | |||
}) | |||
|
|||
router := mux.NewRouter().PathPrefix(prefix).Subrouter() | |||
root := mux.NewRouter().PathPrefix(prefix).Subrouter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why rename it and what difference between root
and clusterRouter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clusterRouter
is a sub router of root
which check the cluster is bootstrapped for all registered handlers.
Rename router
to root
is because there are 2 routers in the function so I think it's better to give another name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to rootRouter
?
server/api/context.go
Outdated
return context.WithValue(ctx, clusterKey, cluster) | ||
} | ||
|
||
func getCtxCluster(ctx context.Context) *server.RaftCluster { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about getCluster
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
Signed-off-by: disksing <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
/merge |
/run-all-tests |
What problem does this PR solve?
Many handlers need to get
RaftCluster
and check if the cluster is bootstrapped.Fix #1905
What is changed and how it works?
Use middleware to eliminate duplicated code.
Check List
Tests
manual test detail
/stores
/store/1
, got not bootstrapped error/stores
/store/1
, no error