Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
chore: use clusters in api endpoint (#249)
Browse files Browse the repository at this point in the history
## Rationale

> There’s no rule on keeping the resource nouns singular or plural,
though it is advisable to keep collections plural.

- https://swagger.io/resources/articles/best-practices-in-api-design/

## Detailed Changes


## Test Plan
No need.
  • Loading branch information
jiacai2050 authored Oct 10, 2023
1 parent 27fad2f commit 70e316e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/service/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ func (a *API) NewAPIRouter() *Router {

// Register cluster API.
router.Get("/clusters", wrap(a.listClusters, true, a.forwardClient))
router.Post("/cluster", wrap(a.createCluster, true, a.forwardClient))
router.Put(fmt.Sprintf("/cluster/:%s", clusterNameParam), wrap(a.updateCluster, true, a.forwardClient))
router.Get(fmt.Sprintf("/cluster/:%s/procedure", clusterNameParam), wrap(a.listProcedures, true, a.forwardClient))
router.Get(fmt.Sprintf("/cluster/:%s/shardAffinities", clusterNameParam), wrap(a.listShardAffinities, true, a.forwardClient))
router.Post(fmt.Sprintf("/cluster/:%s/shardAffinities", clusterNameParam), wrap(a.addShardAffinities, true, a.forwardClient))
router.Del(fmt.Sprintf("/cluster/:%s/shardAffinities", clusterNameParam), wrap(a.removeShardAffinities, true, a.forwardClient))
router.Post("/clusters", wrap(a.createCluster, true, a.forwardClient))
router.Put(fmt.Sprintf("/clusters/:%s", clusterNameParam), wrap(a.updateCluster, true, a.forwardClient))
router.Get(fmt.Sprintf("/clusters/:%s/procedure", clusterNameParam), wrap(a.listProcedures, true, a.forwardClient))
router.Get(fmt.Sprintf("/clusters/:%s/shardAffinities", clusterNameParam), wrap(a.listShardAffinities, true, a.forwardClient))
router.Post(fmt.Sprintf("/clusters/:%s/shardAffinities", clusterNameParam), wrap(a.addShardAffinities, true, a.forwardClient))
router.Del(fmt.Sprintf("/clusters/:%s/shardAffinities", clusterNameParam), wrap(a.removeShardAffinities, true, a.forwardClient))
router.Post("/table/query", wrap(a.queryTable, true, a.forwardClient))
router.Get(fmt.Sprintf("/cluster/:%s/deployMode", clusterNameParam), wrap(a.getDeployMode, true, a.forwardClient))
router.Put(fmt.Sprintf("/cluster/:%s/deployMode", clusterNameParam), wrap(a.updateDeployMode, true, a.forwardClient))

// Register debug API.
router.GetWithoutPrefix("/debug/pprof/profile", pprof.Profile)
Expand All @@ -74,6 +72,8 @@ func (a *API) NewAPIRouter() *Router {
router.GetWithoutPrefix("/debug/pprof/threadCreate", a.pprofThreadcreate)
router.GetWithoutPrefix(fmt.Sprintf("/debug/diagnose/:%s/shards", clusterNameParam), wrap(a.diagnoseShards, true, a.forwardClient))
router.GetWithoutPrefix("/debug/leader", wrap(a.getLeader, false, a.forwardClient))
router.GetWithoutPrefix(fmt.Sprintf("/clusters/:%s/deployMode", clusterNameParam), wrap(a.getDeployMode, true, a.forwardClient))
router.PutWithoutPrefix(fmt.Sprintf("/clusters/:%s/deployMode", clusterNameParam), wrap(a.updateDeployMode, true, a.forwardClient))

// Register ETCD API.
router.Post("/etcd/promoteLearner", wrap(a.etcdAPI.promoteLearner, false, a.forwardClient))
Expand Down
5 changes: 5 additions & 0 deletions server/service/http/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (r *Router) Put(path string, h http.HandlerFunc) {
r.rtr.PUT(r.prefix+path, r.handle(path, h))
}

// PutWithoutPrefix registers a new PUT route without prefix.
func (r *Router) PutWithoutPrefix(path string, h http.HandlerFunc) {
r.rtr.PUT(path, r.handle(path, h))
}

// Post registers a new POST route.
func (r *Router) Post(path string, h http.HandlerFunc) {
r.rtr.POST(r.prefix+path, r.handle(path, h))
Expand Down

0 comments on commit 70e316e

Please sign in to comment.