-
Notifications
You must be signed in to change notification settings - Fork 2
/
asmuxapi.go
36 lines (33 loc) · 1.06 KB
/
asmuxapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"fmt"
"net/http"
"time"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
)
// asmuxDeleteRoom tells asmux to forget about a specific room.
func asmuxDeleteRoom(ctx context.Context, roomID id.RoomID) error {
if len(cfg.AsmuxAccessToken) == 0 {
return fmt.Errorf("asmux access token not set")
} else if cfg.AsmuxMainURL == nil {
return fmt.Errorf("asmux main URL not set")
} else if cfg.DryRun {
time.Sleep(200 * time.Millisecond)
return nil
}
roomURL := mautrix.BuildURL(cfg.AsmuxMainURL, "_matrix", "asmux", "room", roomID).String()
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, roomURL, nil)
if err != nil {
return fmt.Errorf("failed to prepare request: %w", err)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", cfg.AsmuxAccessToken))
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to execute request: %w", err)
} else if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
}
return nil
}