From 4fd5aaf93dae98f018d86afc394c8d42233d9ffd Mon Sep 17 00:00:00 2001 From: Ross Schulman Date: Thu, 16 Nov 2017 18:54:44 -0500 Subject: [PATCH] Fix linting errors and use of httpReq.FormValue Signed-off-by: Ross Schulman --- .../dendrite/federationapi/routing/query.go | 14 ++-- .../dendrite/federationapi/routing/routing.go | 74 +++++++++---------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/query.go b/src/github.com/matrix-org/dendrite/federationapi/routing/query.go index 7e01ef5fd..3aa2e4681 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/query.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/query.go @@ -16,7 +16,8 @@ package routing import ( "net/http" - + "fmt" + "github.com/matrix-org/util" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" @@ -26,16 +27,15 @@ import ( "github.com/matrix-org/gomatrixserverlib" ) +// RoomAliasToID converts the queried alias into a room ID and returns it func RoomAliasToID ( httpReq *http.Request, federation *gomatrixserverlib.FederationClient, - request *gomatrixserverlib.FederationRequest, cfg config.Dendrite, aliasAPI api.RoomserverAliasAPI, - query api.RoomserverQueryAPI, roomAlias string, ) util.JSONResponse { - _, domain, err := gomatrixserverlib.SplitID('#', roomAlias) + _, domain, err := gomatrixserverlib.SplitID('#', httpReq.FormValue("alias")) if err != nil { return util.JSONResponse{ Code: 400, @@ -52,7 +52,7 @@ var resp gomatrixserverlib.RespDirectory return httputil.LogThenError(httpReq, err) } - if len(queryRes.RoomID) > 0 { + if (queryRes.RoomID == "") { // TODO: List servers that are aware of this room alias resp = gomatrixserverlib.RespDirectory{ RoomID: queryRes.RoomID, @@ -62,7 +62,7 @@ var resp gomatrixserverlib.RespDirectory // If the response doesn't contain a non-empty string, return an error return util.JSONResponse{ Code: 404, - JSON: jsonerror.NotFound("Room alias " + roomAlias + " not found."), + JSON: jsonerror.NotFound(fmt.Sprintf("Room alias %s not found", roomAlias)), } } } else { @@ -86,5 +86,5 @@ var resp gomatrixserverlib.RespDirectory return util.JSONResponse{ Code: 200, JSON: resp, -} + } } \ No newline at end of file diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go index 9c4d6c372..f83826946 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -81,45 +81,45 @@ func Setup( )).Methods("PUT", "OPTIONS") v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind", - func(req *http.Request) util.JSONResponse { - return CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) - }, + func(req *http.Request) util.JSONResponse { + return CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) + }, )).Methods("POST", "OPTIONS") - v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI( - "exchange_third_party_invite", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return ExchangeThirdPartyInvite( - httpReq, request, vars["roomID"], query, cfg, federation, producer, - ) - }, - )).Methods("PUT", "OPTIONS") +v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI( + "exchange_third_party_invite", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + vars := mux.Vars(httpReq) + return ExchangeThirdPartyInvite( + httpReq, request, vars["roomID"], query, cfg, federation, producer, + ) + }, +)).Methods("PUT", "OPTIONS") - v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI( - "federation_get_event", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return GetEvent( - httpReq.Context(), request, cfg, query, time.Now(), keys, vars["eventID"], - ) - }, - )).Methods("GET") +v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI( + "federation_get_event", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + vars := mux.Vars(httpReq) + return GetEvent( + httpReq.Context(), request, cfg, query, time.Now(), keys, vars["eventID"], + ) + }, +)).Methods("GET") - v1fedmux.Handle("/version", common.MakeExternalAPI( - "federation_version", - func(httpReq *http.Request) util.JSONResponse { - return Version() - }, - )).Methods("GET") +v1fedmux.Handle("/version", common.MakeExternalAPI( + "federation_version", + func(httpReq *http.Request) util.JSONResponse { + return Version() + }, +)).Methods("GET") - v1fedmux.Handle("/query/directory/?room_alias={alias}", common.MakeFedAPI( - "federation_query_room_alias", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return RoomAliasToID( - httpReq, federation, request, cfg, aliasAPI, query, vars["alias"], - ) - }, - )).Methods("Get") -} +v1fedmux.Handle("/query/directory/?room_alias={alias}", common.MakeFedAPI( + "federation_query_room_alias", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + vars := mux.Vars(httpReq) + return RoomAliasToID( + httpReq, federation, cfg, aliasAPI, vars["alias"], + ) + }, +)).Methods("Get") +} \ No newline at end of file