mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add liveness and readiness endpoints to appservices
This commit is contained in:
parent
53be7e7ac8
commit
386ac2e0c6
2 changed files with 27 additions and 0 deletions
|
|
@ -46,6 +46,8 @@ func Create() *AppService {
|
|||
StateStore: NewBasicStateStore(),
|
||||
Router: mux.NewRouter(),
|
||||
UserAgent: mautrix.DefaultUserAgent,
|
||||
Live: true,
|
||||
Ready: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +107,9 @@ type AppService struct {
|
|||
|
||||
DefaultHTTPRetries int
|
||||
|
||||
Live bool
|
||||
Ready bool
|
||||
|
||||
clients map[id.UserID]*mautrix.Client
|
||||
clientsLock sync.RWMutex
|
||||
intents map[id.UserID]*IntentAPI
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ func (as *AppService) Start() {
|
|||
as.Router.HandleFunc("/_matrix/app/v1/transactions/{txnID}", as.PutTransaction).Methods(http.MethodPut)
|
||||
as.Router.HandleFunc("/_matrix/app/v1/rooms/{roomAlias}", as.GetRoom).Methods(http.MethodGet)
|
||||
as.Router.HandleFunc("/_matrix/app/v1/users/{userID}", as.GetUser).Methods(http.MethodGet)
|
||||
as.Router.HandleFunc("/_matrix/mau/live", as.GetLive).Methods(http.MethodGet)
|
||||
as.Router.HandleFunc("/_matrix/mau/ready", as.GetReady).Methods(http.MethodGet)
|
||||
|
||||
var err error
|
||||
as.server = &http.Server{
|
||||
|
|
@ -237,3 +239,23 @@ func (as *AppService) GetUser(w http.ResponseWriter, r *http.Request) {
|
|||
}.Write(w)
|
||||
}
|
||||
}
|
||||
|
||||
func (as *AppService) GetLive(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
if as.Live {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
w.Write([]byte("{}"))
|
||||
}
|
||||
|
||||
func (as *AppService) GetReady(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
if as.Ready {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
w.Write([]byte("{}"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue