Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client to clients which need to make outbound HTTP requests. Due to Setup being used to call many other functions, a gocyclo nolint is applied: nolint: gocyclo
( publicAPIMux, wkMux, synapseAdminRouter, dendriteAdminRouter *mux.Router, cfg *config.ClientAPI, rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI, userAPI userapi.ClientUserAPI, userDirectoryProvider userapi.QuerySearchProfilesAPI, federation *gomatrixserverlib.FederationClient, syncProducer *producers.SyncAPIProducer, transactionsCache *transactions.Cache, federationSender federationAPI.ClientFederationAPI, keyAPI keyserverAPI.ClientKeyAPI, extRoomsProvider api.ExtraPublicRoomsProvider, mscCfg *config.MSCs, natsClient *nats.Conn, )
| 48 | // applied: |
| 49 | // nolint: gocyclo |
| 50 | func Setup( |
| 51 | publicAPIMux, wkMux, synapseAdminRouter, dendriteAdminRouter *mux.Router, |
| 52 | cfg *config.ClientAPI, |
| 53 | rsAPI roomserverAPI.ClientRoomserverAPI, |
| 54 | asAPI appserviceAPI.AppServiceInternalAPI, |
| 55 | userAPI userapi.ClientUserAPI, |
| 56 | userDirectoryProvider userapi.QuerySearchProfilesAPI, |
| 57 | federation *gomatrixserverlib.FederationClient, |
| 58 | syncProducer *producers.SyncAPIProducer, |
| 59 | transactionsCache *transactions.Cache, |
| 60 | federationSender federationAPI.ClientFederationAPI, |
| 61 | keyAPI keyserverAPI.ClientKeyAPI, |
| 62 | extRoomsProvider api.ExtraPublicRoomsProvider, |
| 63 | mscCfg *config.MSCs, natsClient *nats.Conn, |
| 64 | ) { |
| 65 | prometheus.MustRegister(amtRegUsers, sendEventDuration) |
| 66 | |
| 67 | rateLimits := httputil.NewRateLimits(&cfg.RateLimiting) |
| 68 | userInteractiveAuth := auth.NewUserInteractive(userAPI, cfg) |
| 69 | |
| 70 | unstableFeatures := map[string]bool{ |
| 71 | "org.matrix.e2e_cross_signing": true, |
| 72 | } |
| 73 | for _, msc := range cfg.MSCs.MSCs { |
| 74 | unstableFeatures["org.matrix."+msc] = true |
| 75 | } |
| 76 | |
| 77 | if cfg.Matrix.WellKnownClientName != "" { |
| 78 | logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName) |
| 79 | wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse { |
| 80 | return util.JSONResponse{ |
| 81 | Code: http.StatusOK, |
| 82 | JSON: struct { |
| 83 | HomeserverName struct { |
| 84 | BaseUrl string `json:"base_url"` |
| 85 | } `json:"m.homeserver"` |
| 86 | }{ |
| 87 | HomeserverName: struct { |
| 88 | BaseUrl string `json:"base_url"` |
| 89 | }{ |
| 90 | BaseUrl: cfg.Matrix.WellKnownClientName, |
| 91 | }, |
| 92 | }, |
| 93 | } |
| 94 | })).Methods(http.MethodGet, http.MethodOptions) |
| 95 | } |
| 96 | |
| 97 | publicAPIMux.Handle("/versions", |
| 98 | httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse { |
| 99 | return util.JSONResponse{ |
| 100 | Code: http.StatusOK, |
| 101 | JSON: struct { |
| 102 | Versions []string `json:"versions"` |
| 103 | UnstableFeatures map[string]bool `json:"unstable_features"` |
| 104 | }{Versions: []string{ |
| 105 | "r0.0.1", |
| 106 | "r0.1.0", |
| 107 | "r0.2.0", |
nothing calls this directly
no test coverage detected