-
Notifications
You must be signed in to change notification settings - Fork 0
/
maildb.go
43 lines (35 loc) · 937 Bytes
/
maildb.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
37
38
39
40
41
42
43
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
config "github.com/mailway-app/config"
"github.com/pkg/errors"
)
func updateMailStatus(jwt string, domain string, uuid string, status int) error {
client := &http.Client{
Timeout: 5 * time.Second,
}
url := fmt.Sprintf("http://127.0.0.1:%d/db/domain/%s/update/%s", config.CurrConfig.PortMaildb, domain, uuid)
body := fmt.Sprintf("{\"status\":%d}", status)
req, err := http.NewRequest(http.MethodPut, url, strings.NewReader(body))
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+jwt)
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
return errors.Wrap(err, "could not read response body")
}
return errors.Errorf("maildb returned code %d: %s", res.StatusCode, bodyBytes)
}
return nil
}