Update matrix.go to use new logger, fix up outputs

This commit is contained in:
Amarpreet Minhas 2023-04-29 14:01:52 -04:00
parent f5ec960eb2
commit 4747b15d62

View file

@ -6,28 +6,13 @@ import (
"net/http"
"git.minhas.io/asara/well-goknown/config"
"git.minhas.io/asara/well-goknown/logger"
)
type matrixServerWellKnown struct {
WellKnownAddress string `json:"m.server"`
}
func MatrixServer(w http.ResponseWriter, req *http.Request) {
// uses an environment variable for now
wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
wellKnown := &matrixServerWellKnown{
WellKnownAddress: wellKnownAddr,
}
json.NewEncoder(w).Encode(wellKnown)
}
type matrixBaseUrl struct {
BaseUrl string `json:"base_url"`
}
@ -41,11 +26,31 @@ type matrixClientWellKnown struct {
IdentityServer *matrixIdentityServer `json:"m.identity_server,omitempty"`
}
func MatrixClient(w http.ResponseWriter, req *http.Request) {
func MatrixServer(w http.ResponseWriter, req *http.Request) {
l := logger.Get()
// uses an environment variable for now
wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound)
l.Debug().Str("path", "matrix/server").Msg("matrix well known address unset")
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
wellKnown := &matrixServerWellKnown{
WellKnownAddress: wellKnownAddr,
}
json.NewEncoder(w).Encode(wellKnown)
}
func MatrixClient(w http.ResponseWriter, req *http.Request) {
l := logger.Get()
// uses an environment variable for now
wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound)
l.Debug().Str("path", "matrix/client").Msg("matrix well known address unset")
return
}