mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
Extract inline struct from well-known client response
This commit is contained in:
parent
886c004c7d
commit
fad5300c5a
|
|
@ -44,6 +44,19 @@ import (
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WellKnownClientHomeserver struct {
|
||||||
|
BaseUrl string `json:"base_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WellKnownSlidingSyncProxy struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WellKnownClientResponse struct {
|
||||||
|
HomeserverName WellKnownClientHomeserver `json:"m.homeserver"`
|
||||||
|
SlidingSyncProxy *WellKnownSlidingSyncProxy `json:"org.matrix.msc3575.proxy,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
||||||
// to clients which need to make outbound HTTP requests.
|
// to clients which need to make outbound HTTP requests.
|
||||||
//
|
//
|
||||||
|
|
@ -98,48 +111,22 @@ func Setup(
|
||||||
logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName)
|
logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName)
|
||||||
if cfg.Matrix.WellKnownSlidingSyncProxy != "" {
|
if cfg.Matrix.WellKnownSlidingSyncProxy != "" {
|
||||||
logrus.Infof("Setting org.matrix.msc3575.proxy url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownSlidingSyncProxy)
|
logrus.Infof("Setting org.matrix.msc3575.proxy url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownSlidingSyncProxy)
|
||||||
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: struct {
|
|
||||||
HomeserverName struct {
|
|
||||||
BaseUrl string `json:"base_url"`
|
|
||||||
} `json:"m.homeserver"`
|
|
||||||
SlidingSyncProxy struct {
|
|
||||||
Url string `json:"url"`
|
|
||||||
} `json:"org.matrix.msc3575.proxy"`
|
|
||||||
}{
|
|
||||||
HomeserverName: struct {
|
|
||||||
BaseUrl string `json:"base_url"`
|
|
||||||
}{
|
|
||||||
BaseUrl: cfg.Matrix.WellKnownClientName,
|
|
||||||
},
|
|
||||||
SlidingSyncProxy: struct {
|
|
||||||
Url string `json:"url"`
|
|
||||||
}{
|
|
||||||
Url: cfg.Matrix.WellKnownSlidingSyncProxy,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})).Methods(http.MethodGet, http.MethodOptions)
|
|
||||||
} else {
|
|
||||||
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusOK,
|
|
||||||
JSON: struct {
|
|
||||||
HomeserverName struct {
|
|
||||||
BaseUrl string `json:"base_url"`
|
|
||||||
} `json:"m.homeserver"`
|
|
||||||
}{
|
|
||||||
HomeserverName: struct {
|
|
||||||
BaseUrl string `json:"base_url"`
|
|
||||||
}{
|
|
||||||
BaseUrl: cfg.Matrix.WellKnownClientName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})).Methods(http.MethodGet, http.MethodOptions)
|
|
||||||
}
|
}
|
||||||
|
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
|
||||||
|
response := WellKnownClientResponse{
|
||||||
|
HomeserverName: WellKnownClientHomeserver{cfg.Matrix.WellKnownClientName},
|
||||||
|
}
|
||||||
|
if cfg.Matrix.WellKnownSlidingSyncProxy != "" {
|
||||||
|
response.SlidingSyncProxy = &WellKnownSlidingSyncProxy{
|
||||||
|
Url: cfg.Matrix.WellKnownSlidingSyncProxy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: response,
|
||||||
|
}
|
||||||
|
})).Methods(http.MethodGet, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
publicAPIMux.Handle("/versions",
|
publicAPIMux.Handle("/versions",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue