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

cmd/dcrdata: version dcrdata APIs #1951

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/dcrdata/internal/api/apirouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type apiMux struct {
*chi.Mux
}

// Version returns the version of this API handler.
func (am *apiMux) Version() int {
return APIVersion
}

type fileMux struct {
*chi.Mux
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/dcrdata/internal/api/insight/apirouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ type ApiMux struct {
*chi.Mux
}

// APIVersion is an integer value, incremented for breaking changes
const APIVersion = 0
// Version returns the version of this API handler.
func (am *ApiMux) Version() int {
return APIVersion
}

// NewInsightAPIRouter returns a new HTTP path router, ApiMux, for the Insight
// API, app.
Expand Down
4 changes: 4 additions & 0 deletions cmd/dcrdata/internal/api/insight/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package insight

// APIVersion is an integer value, incremented for breaking changes
const APIVersion = 1
13 changes: 11 additions & 2 deletions cmd/dcrdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,24 @@ func _main(ctx context.Context) error {
// SyncStatusAPIIntercept returns a json response if the sync status page is
// enabled (no the full explorer while syncing).
webMux.With(explore.SyncStatusAPIIntercept).Group(func(r chi.Router) {
// Mount the dcrdata's REST API.
// Mount the default dcrdata REST API.
r.Mount("/api", apiMux.Mux)
// Setup and mount the Insight API.
// Mount the versioned dcrdata REST API.
versionPrefix := fmt.Sprintf("/api/v%d", apiMux.Version())
r.Mount(versionPrefix, apiMux.Mux)

// Setup the Insight API.
insightApp := insight.NewInsightAPI(dcrdClient, chainDB,
activeChain, mpm, cfg.IndentJSON, app.Status)
insightApp.SetReqRateLimit(cfg.InsightReqRateLimit)
insightMux := insight.NewInsightAPIRouter(insightApp, cfg.UseRealIP,
cfg.CompressAPI, cfg.MaxCSVAddrs)

// Mount the default dcrdata insight REST API.
r.Mount("/insight/api", insightMux.Mux)
// Mount the versioned dcrdata insight REST API.
insightVersionPrefix := fmt.Sprintf("/insight/api/v%d", insightMux.Version())
r.Mount(insightVersionPrefix, insightMux.Mux)
ukane-philemon marked this conversation as resolved.
Show resolved Hide resolved

if insightSocketServer != nil {
r.With(mw.NoOrigin).Get("/insight/socket.io/", insightSocketServer.ServeHTTP)
Expand Down