mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
Add request and response types
Signed-off-by: Prashanth Pai <ppai@redhat.com>
This commit is contained in:
102
endpoints.md
102
endpoints.md
@@ -1,54 +1,52 @@
|
||||
# API Endpoints
|
||||
|
||||
Name | Methods | Path
|
||||
--- | --- | ---
|
||||
GetVersion | [GET] | /version
|
||||
VolumeCreate | [POST] | /v1/volumes
|
||||
VolumeExpand | [POST] | /v1/volumes/{volname}/expand
|
||||
VolumeOptions | [POST] | /v1/volumes/{volname}/options
|
||||
OptionGroupList | [GET] | /v1/volumes/options-group
|
||||
OptionGroupCreate | [POST] | /v1/volumes/options-group
|
||||
OptionGroupDelete | [DELETE] | /v1/volumes/options-group/{groupname}
|
||||
VolumeDelete | [DELETE] | /v1/volumes/{volname}
|
||||
VolumeInfo | [GET] | /v1/volumes/{volname}
|
||||
VolumeBricksStatus | [GET] | /v1/volumes/{volname}/bricks
|
||||
VolumeStatus | [GET] | /v1/volumes/{volname}/status
|
||||
VolumeList | [GET] | /v1/volumes
|
||||
VolumeStart | [POST] | /v1/volumes/{volname}/start
|
||||
VolumeStop | [POST] | /v1/volumes/{volname}/stop
|
||||
VolfilesGenerate | [POST] | /v1/volfiles
|
||||
VolfilesGet | [GET] | /v1/volfiles
|
||||
GetPeer | [GET] | /v1/peers/{peerid}
|
||||
GetPeers | [GET] | /v1/peers
|
||||
DeletePeer | [DELETE] | /v1/peers/{peerid}
|
||||
AddPeer | [POST] | /v1/peers
|
||||
GeoreplicationCreate | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}
|
||||
GeoreplicationStart | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}/start
|
||||
GeoreplicationStop | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}/stop
|
||||
GeoreplicationDelete | [DELETE] | /v1/geo-replication/{mastervolid}/{remotevolid}
|
||||
GeoreplicationPause | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}/pause
|
||||
GeoreplicationResume | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}/resume
|
||||
GeoreplicationStatus | [GET] | /v1/geo-replication/{mastervolid}/{remotevolid}
|
||||
GeoReplicationConfigGet | [GET] | /v1/geo-replication/{mastervolid}/{remotevolid}/config
|
||||
GeoReplicationConfigSet | [POST] | /v1/geo-replication/{mastervolid}/{remotevolid}/config
|
||||
GeoReplicationConfigReset | [DELETE] | /v1/geo-replication/{mastervolid}/{remotevolid}/config
|
||||
GeoreplicationStatusList | [GET] | /v1/geo-replication
|
||||
GeoreplicationSshKeyGenerate | [POST] | /v1/ssh-key/{volname}/generate
|
||||
GeoreplicationSshKeyPush | [POST] | /v1/ssh-key/{volname}/push
|
||||
GeoreplicationSshKeyGet | [GET] | /v1/ssh-key/{volname}
|
||||
BitrotEnable | [POST] | /v1/volumes/{volname}/bitrot/enable
|
||||
BitrotDisable | [POST] | /v1/volumes/{volname}/bitrot/disable
|
||||
ScrubOndemand | [POST] | /v1/volumes/{volname}/bitrot/scrubondemand
|
||||
ScrubStatus | [GET] | /v1/volumes/{volname}/bitrot/scrubstatus
|
||||
QuotaEnable | [POST] | /v1/quota/{volname}
|
||||
QuotaDisable | [DELETE] | /v1/quota/{volname}
|
||||
QuotaList | [GET] | /v1/quota/{volname}/limit
|
||||
QuotaLimit | [POST] | /v1/quota/{volname}/limit
|
||||
QuotaRemove | [DELETE] | /v1/quota/{volname}/limit
|
||||
WebhookAdd | [POST] | /v1/events/webhook
|
||||
WebhookDelete | [DELETE] | /v1/events/webhook
|
||||
WebhookList | [GET] | /v1/events/webhook
|
||||
GlustershEnable | [POST] | /v1/volumes/{name}/heal/enable
|
||||
GlustershDisable | [POST] | /v1/volumes/{name}/heal/disable
|
||||
Statedump | [GET] | /statedump
|
||||
List Endpoints | [GET] | /endpoints
|
||||
Name | Methods | Path | Request | Response
|
||||
--- | --- | --- | --- | ---
|
||||
GetVersion | GET | /version | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [VersionResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VersionResp)
|
||||
VolumeCreate | POST | /volumes | [VolCreateReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolCreateReq) | [VolumeCreateResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolumeCreateResp)
|
||||
VolumeExpand | POST | /volumes/{volname}/expand | [VolExpandReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolExpandReq) | [VolumeExpandResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolumeExpandResp)
|
||||
VolumeOptions | POST | /volumes/{volname}/options | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
OptionGroupList | GET | /volumes/options-group | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [OptionGroupListResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#OptionGroupListResp)
|
||||
OptionGroupCreate | POST | /volumes/options-group | [OptionGroupReq](https://godoc.org/github.com/gluster/glusterd2/pkg/api#OptionGroupReq) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
OptionGroupDelete | DELETE | /volumes/options-group/{groupname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
VolumeDelete | DELETE | /volumes/{volname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
VolumeInfo | GET | /volumes/{volname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [VolumeGetResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolumeGetResp)
|
||||
VolumeBricksStatus | GET | /volumes/{volname}/bricks | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [BricksStatusResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#BricksStatusResp)
|
||||
VolumeStatus | GET | /volumes/{volname}/status | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [VolumeStatusResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolumeStatusResp)
|
||||
VolumeList | GET | /volumes | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [VolumeListResp](https://godoc.org/github.com/gluster/glusterd2/pkg/api#VolumeListResp)
|
||||
VolumeStart | POST | /volumes/{volname}/start | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
VolumeStop | POST | /volumes/{volname}/stop | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
VolfilesGenerate | POST | /volfiles | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
VolfilesGet | GET | /volfiles | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GetPeer | GET | /peers/{peerid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GetPeers | GET | /peers | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
DeletePeer | DELETE | /peers/{peerid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
AddPeer | POST | /peers | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationCreate | POST | /geo-replication/{mastervolid}/{remotevolid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationStart | POST | /geo-replication/{mastervolid}/{remotevolid}/start | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationStop | POST | /geo-replication/{mastervolid}/{remotevolid}/stop | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationDelete | DELETE | /geo-replication/{mastervolid}/{remotevolid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationPause | POST | /geo-replication/{mastervolid}/{remotevolid}/pause | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationResume | POST | /geo-replication/{mastervolid}/{remotevolid}/resume | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationStatus | GET | /geo-replication/{mastervolid}/{remotevolid} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoReplicationConfigGet | GET | /geo-replication/{mastervolid}/{remotevolid}/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoReplicationConfigSet | POST | /geo-replication/{mastervolid}/{remotevolid}/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoReplicationConfigReset | DELETE | /geo-replication/{mastervolid}/{remotevolid}/config | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationStatusList | GET | /geo-replication | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationSshKeyGenerate | POST | /ssh-key/{volname}/generate | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationSshKeyPush | POST | /ssh-key/{volname}/push | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GeoreplicationSshKeyGet | GET | /ssh-key/{volname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
BitrotEnable | POST | /volumes/{volname}/bitrot/enable | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
BitrotDisable | POST | /volumes/{volname}/bitrot/disable | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
ScrubOndemand | POST | /volumes/{volname}/bitrot/scrubondemand | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
ScrubStatus | GET | /volumes/{volname}/bitrot/scrubstatus | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
QuotaEnable | POST | /quota/{volname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
QuotaDisable | DELETE | /quota/{volname} | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
QuotaList | GET | /quota/{volname}/limit | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
QuotaLimit | POST | /quota/{volname}/limit | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
QuotaRemove | DELETE | /quota/{volname}/limit | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
WebhookAdd | POST | /events/webhook | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
WebhookDelete | DELETE | /events/webhook | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
WebhookList | GET | /events/webhook | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GlustershEnable | POST | /volumes/{name}/heal/enable | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
GlustershDisable | POST | /volumes/{name}/heal/disable | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#) | [](https://godoc.org/github.com/gluster/glusterd2/pkg/api#)
|
||||
|
||||
@@ -3,6 +3,8 @@ package versioncommands
|
||||
|
||||
import (
|
||||
"github.com/gluster/glusterd2/glusterd2/servers/rest/route"
|
||||
"github.com/gluster/glusterd2/pkg/api"
|
||||
"github.com/gluster/glusterd2/pkg/utils"
|
||||
)
|
||||
|
||||
// Command is a holding struct used to implement the GlusterD Command interface
|
||||
@@ -13,10 +15,11 @@ type Command struct {
|
||||
func (c *Command) Routes() route.Routes {
|
||||
return route.Routes{
|
||||
route.Route{
|
||||
Name: "GetVersion",
|
||||
Method: "GET",
|
||||
Pattern: "/version",
|
||||
HandlerFunc: getVersionHandler,
|
||||
Name: "GetVersion",
|
||||
Method: "GET",
|
||||
Pattern: "/version",
|
||||
HandlerFunc: getVersionHandler,
|
||||
ResponseType: utils.GetTypeString((*api.VersionResp)(nil)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package volumecommands
|
||||
|
||||
import (
|
||||
"github.com/gluster/glusterd2/glusterd2/servers/rest/route"
|
||||
"github.com/gluster/glusterd2/pkg/api"
|
||||
"github.com/gluster/glusterd2/pkg/utils"
|
||||
)
|
||||
|
||||
// Command is a holding struct used to implement the GlusterD Command interface
|
||||
@@ -13,17 +15,21 @@ type Command struct {
|
||||
func (c *Command) Routes() route.Routes {
|
||||
return route.Routes{
|
||||
route.Route{
|
||||
Name: "VolumeCreate",
|
||||
Method: "POST",
|
||||
Pattern: "/volumes",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeCreateHandler},
|
||||
Name: "VolumeCreate",
|
||||
Method: "POST",
|
||||
Pattern: "/volumes",
|
||||
Version: 1,
|
||||
RequestType: utils.GetTypeString((*api.VolCreateReq)(nil)),
|
||||
ResponseType: utils.GetTypeString((*api.VolumeCreateResp)(nil)),
|
||||
HandlerFunc: volumeCreateHandler},
|
||||
route.Route{
|
||||
Name: "VolumeExpand",
|
||||
Method: "POST",
|
||||
Pattern: "/volumes/{volname}/expand",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeExpandHandler},
|
||||
Name: "VolumeExpand",
|
||||
Method: "POST",
|
||||
Pattern: "/volumes/{volname}/expand",
|
||||
Version: 1,
|
||||
RequestType: utils.GetTypeString((*api.VolExpandReq)(nil)),
|
||||
ResponseType: utils.GetTypeString((*api.VolumeExpandResp)(nil)),
|
||||
HandlerFunc: volumeExpandHandler},
|
||||
// TODO: Implmement volume reset as
|
||||
// DELETE /volumes/{volname}/options
|
||||
route.Route{
|
||||
@@ -33,16 +39,18 @@ func (c *Command) Routes() route.Routes {
|
||||
Version: 1,
|
||||
HandlerFunc: volumeOptionsHandler},
|
||||
route.Route{
|
||||
Name: "OptionGroupList",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/options-group",
|
||||
Version: 1,
|
||||
HandlerFunc: optionGroupListHandler},
|
||||
Name: "OptionGroupList",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/options-group",
|
||||
Version: 1,
|
||||
ResponseType: utils.GetTypeString((*api.OptionGroupListResp)(nil)),
|
||||
HandlerFunc: optionGroupListHandler},
|
||||
route.Route{
|
||||
Name: "OptionGroupCreate",
|
||||
Method: "POST",
|
||||
Pattern: "/volumes/options-group",
|
||||
Version: 1,
|
||||
RequestType: utils.GetTypeString((*api.OptionGroupReq)(nil)),
|
||||
HandlerFunc: optionGroupCreateHandler},
|
||||
route.Route{
|
||||
Name: "OptionGroupDelete",
|
||||
@@ -57,29 +65,33 @@ func (c *Command) Routes() route.Routes {
|
||||
Version: 1,
|
||||
HandlerFunc: volumeDeleteHandler},
|
||||
route.Route{
|
||||
Name: "VolumeInfo",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeInfoHandler},
|
||||
Name: "VolumeInfo",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}",
|
||||
Version: 1,
|
||||
ResponseType: utils.GetTypeString((*api.VolumeGetResp)(nil)),
|
||||
HandlerFunc: volumeInfoHandler},
|
||||
route.Route{
|
||||
Name: "VolumeBricksStatus",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}/bricks",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeBricksStatusHandler},
|
||||
Name: "VolumeBricksStatus",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}/bricks",
|
||||
Version: 1,
|
||||
ResponseType: utils.GetTypeString((*api.BricksStatusResp)(nil)),
|
||||
HandlerFunc: volumeBricksStatusHandler},
|
||||
route.Route{
|
||||
Name: "VolumeStatus",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}/status",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeStatusHandler},
|
||||
Name: "VolumeStatus",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes/{volname}/status",
|
||||
Version: 1,
|
||||
ResponseType: utils.GetTypeString((*api.VolumeStatusResp)(nil)),
|
||||
HandlerFunc: volumeStatusHandler},
|
||||
route.Route{
|
||||
Name: "VolumeList",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes",
|
||||
Version: 1,
|
||||
HandlerFunc: volumeListHandler},
|
||||
Name: "VolumeList",
|
||||
Method: "GET",
|
||||
Pattern: "/volumes",
|
||||
Version: 1,
|
||||
ResponseType: utils.GetTypeString((*api.VolumeListResp)(nil)),
|
||||
HandlerFunc: volumeListHandler},
|
||||
route.Route{
|
||||
Name: "VolumeStart",
|
||||
Method: "POST",
|
||||
|
||||
@@ -130,24 +130,16 @@ func (r *GDRest) Stop() {
|
||||
func (r *GDRest) listEndpointsHandler() http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
var resp api.ListEndpointsResp
|
||||
walker := func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
|
||||
t, err := route.GetPathTemplate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := route.GetMethods()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp = append(resp, api.Endpoint{
|
||||
Name: route.GetName(),
|
||||
Methods: m,
|
||||
Path: t,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
ctx := req.Context()
|
||||
r.Routes.Walk(walker)
|
||||
for _, r := range AllRoutes {
|
||||
resp = append(resp, api.Endpoint{
|
||||
Name: r.Name,
|
||||
Method: r.Method,
|
||||
Path: r.Pattern,
|
||||
RequestType: r.RequestType,
|
||||
ResponseType: r.ResponseType,
|
||||
})
|
||||
}
|
||||
restutils.SendHTTPResponse(ctx, w, http.StatusOK, resp)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,11 +9,14 @@ import (
|
||||
// This route style comes from the tutorial on
|
||||
// http://thenewstack.io/make-a-restful-json-api-go/
|
||||
type Route struct {
|
||||
Name string
|
||||
Method string
|
||||
Pattern string
|
||||
Version int
|
||||
HandlerFunc http.HandlerFunc
|
||||
Name string
|
||||
Description string
|
||||
Method string
|
||||
Pattern string
|
||||
Version int
|
||||
RequestType string
|
||||
ResponseType string // Success
|
||||
HandlerFunc http.HandlerFunc
|
||||
}
|
||||
|
||||
// Routes is a table of many Route's
|
||||
|
||||
@@ -10,11 +10,15 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// AllRoutes is global list of all API endpoints
|
||||
var AllRoutes route.Routes
|
||||
|
||||
// setRoutes adds the given routes to the GlusterD Rest server
|
||||
func (r *GDRest) setRoutes(routes route.Routes) {
|
||||
var urlPattern string
|
||||
for _, route := range routes {
|
||||
var urlPattern string
|
||||
if route.Name == "GetVersion" {
|
||||
// Set routes in mux.Routes
|
||||
if route.Version == 0 {
|
||||
urlPattern = route.Pattern
|
||||
} else {
|
||||
urlPattern = fmt.Sprintf("/v%d%s", route.Version, route.Pattern)
|
||||
@@ -23,13 +27,15 @@ func (r *GDRest) setRoutes(routes route.Routes) {
|
||||
"name": route.Name,
|
||||
"path": urlPattern,
|
||||
"method": route.Method,
|
||||
}).Debug("Registering new route")
|
||||
|
||||
}).Debug("Registering new mux route")
|
||||
r.Routes.
|
||||
Methods(route.Method).
|
||||
Path(urlPattern).
|
||||
Name(route.Name).
|
||||
Handler(route.HandlerFunc)
|
||||
|
||||
// Set our global copy of all routes
|
||||
AllRoutes = append(AllRoutes, route)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ package api
|
||||
|
||||
// Endpoint represents an HTTP API endpoint.
|
||||
type Endpoint struct {
|
||||
Name string `json:"name"`
|
||||
Methods []string `json:"methods"`
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Method string `json:"methods"`
|
||||
Path string `json:"path"`
|
||||
RequestType string `json:"request-type"`
|
||||
ResponseType string `json:"response-type"`
|
||||
}
|
||||
|
||||
// ListEndpointsResp is the response sent to client for a list endpoints request.
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/gluster/glusterd2/pkg/api"
|
||||
@@ -14,9 +15,9 @@ import (
|
||||
|
||||
const endpointsTable = `# API Endpoints
|
||||
|
||||
Name | Methods | Path
|
||||
--- | --- | ---{{range $index, $element := .}}
|
||||
{{.Name}} | {{.Methods}} | {{.Path}}{{end}}
|
||||
Name | Methods | Path | Request | Response
|
||||
--- | --- | --- | --- | ---{{range $index, $element := .}}
|
||||
{{.Name}} | {{.Method}} | {{.Path}} | [{{.RequestType}}](https://godoc.org/github.com/gluster/glusterd2/pkg/api#{{.RequestType}}) | [{{.ResponseType}}](https://godoc.org/github.com/gluster/glusterd2/pkg/api#{{.ResponseType}}){{end}}
|
||||
`
|
||||
|
||||
const outFile = "endpoints.md"
|
||||
@@ -42,6 +43,14 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var tmp []string
|
||||
for i := range endpoints {
|
||||
tmp = strings.Split(endpoints[i].RequestType, ".")
|
||||
endpoints[i].RequestType = tmp[len(tmp)-1]
|
||||
tmp = strings.Split(endpoints[i].ResponseType, ".")
|
||||
endpoints[i].ResponseType = tmp[len(tmp)-1]
|
||||
}
|
||||
|
||||
f, err := os.Create(outFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
10
pkg/utils/types.go
Normal file
10
pkg/utils/types.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "reflect"
|
||||
|
||||
// GetTypeString returns the type of instance passed, as a string.
|
||||
// Go doesn't have type literals. Hence one has to pass (*Type)(nil)
|
||||
// as argument to this function.
|
||||
func GetTypeString(i interface{}) string {
|
||||
return reflect.TypeOf(i).Elem().String()
|
||||
}
|
||||
Reference in New Issue
Block a user