Skip to content

Commit 0ce5f8d

Browse files
Fix
1 parent 30bc01c commit 0ce5f8d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

code/go/0chain.net/blobbercore/handler/handler.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ func WithBlobberRegistered(h http.Handler) http.Handler {
147147
}
148148

149149
/*setupHandlers sets up the necessary API end points */
150-
func setupHandlers(r *mux.Router) {
150+
func setupHandlers(s *mux.Router) {
151151
ConfigRateLimits()
152152

153-
s := r.NewRoute().Subrouter()
154153
s.Use(UseRecovery, UseCors, WithBlobberRegistered)
155154

156155
s.HandleFunc("/_stats", RateLimitByCommmitRL(StatsHandler))
@@ -273,11 +272,6 @@ func setupHandlers(r *mux.Router) {
273272
RateLimitByGeneralRL(WithTxHandler(LoadPlaylistFile))).
274273
Methods(http.MethodGet, http.MethodOptions)
275274

276-
s.HandleFunc("/v1/file/list/{allocation}",
277-
RateLimitByObjectRL(common.ToJSONResponse(WithReadOnlyConnection(ListHandler)))).
278-
Methods(http.MethodGet, http.MethodOptions)
279-
s.HandleFunc("/v1/file/upload/{allocation}", RateLimitByFileRL(common.ToJSONResponse(WithConnection(UploadHandler))))
280-
s.HandleFunc("/v1/file/download/{allocation}", RateLimitByFileRL(common.ToByteStream(WithConnection(DownloadHandler)))).Methods(http.MethodGet, http.MethodOptions)
281275
}
282276

283277
func WithReadOnlyConnection(handler common.JSONResponderF) common.JSONResponderF {

code/go/0chain.net/blobbercore/handler/handler_integration_tests.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ import (
2020
/* SetupHandlers sets up the necessary API end points */
2121
func SetupHandlers(r *mux.Router) {
2222
r.HandleFunc("/_blobber_info", RateLimitByCommmitRL(common.ToJSONResponse(GetBlobberInfo)))
23-
setupHandlers(r)
23+
24+
s := r.NewRoute().Subrouter()
25+
setupHandlers(s)
26+
27+
s.HandleFunc("/v1/file/list/{allocation}",
28+
RateLimitByObjectRL(common.ToJSONOrNotResponse(WithReadOnlyConnection(ListHandler)))).
29+
Methods(http.MethodGet, http.MethodOptions)
30+
s.HandleFunc("/v1/file/upload/{allocation}", RateLimitByFileRL(common.ToJSONOrNotResponse(WithConnection(UploadHandler))))
31+
s.HandleFunc("/v1/file/download/{allocation}", RateLimitByFileRL(ToByteStreamOrNot(WithConnection(DownloadHandler)))).Methods(http.MethodGet, http.MethodOptions)
2432
}
2533

2634
func WithReadOnlyConnectionNotRespond(handler common.JSONResponderOrNotF) common.JSONResponderOrNotF {

code/go/0chain.net/blobbercore/handler/handler_main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import (
1313
/* SetupHandlers sets up the necessary API end points */
1414
func SetupHandlers(r *mux.Router) {
1515
r.HandleFunc("/_blobber_info", RateLimitByCommmitRL(common.ToJSONResponse(GetBlobberInfo)))
16-
setupHandlers(r)
16+
17+
s := r.NewRoute().Subrouter()
18+
setupHandlers(s)
19+
20+
s.HandleFunc("/v1/file/list/{allocation}",
21+
RateLimitByObjectRL(common.ToJSONResponse(WithReadOnlyConnection(ListHandler)))).
22+
Methods(http.MethodGet, http.MethodOptions)
23+
s.HandleFunc("/v1/file/upload/{allocation}", RateLimitByFileRL(common.ToJSONResponse(WithConnection(UploadHandler))))
24+
s.HandleFunc("/v1/file/download/{allocation}", RateLimitByFileRL(common.ToByteStream(WithConnection(DownloadHandler)))).Methods(http.MethodGet, http.MethodOptions)
1725
}
1826

1927
func ListHandler(ctx context.Context, r *http.Request) (interface{}, error) {

0 commit comments

Comments
 (0)