Skip to content

Commit 991a583

Browse files
committed
More experiments
1 parent 1aaa345 commit 991a583

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

api/cmd/experiments/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package main
22

33
import (
4+
"bytes"
45
"context"
6+
"encoding/json"
57
"fmt"
8+
"io"
69
"log"
10+
"net/http"
711
"os"
812
"strings"
913
"sync"
@@ -30,6 +34,8 @@ func main() {
3034
logger := container.Logger()
3135

3236
logger.Info("Starting experiments")
37+
38+
sendSingle()
3339
}
3440

3541
func chunkBy[T any](items []T, chunkSize int) (chunks [][]T) {
@@ -92,6 +98,40 @@ func loadTest() {
9298
wg.Wait()
9399
}
94100

101+
func sendSingle() {
102+
payload, err := json.Marshal(map[string]any{
103+
"content": fmt.Sprintf("This is a test text message"),
104+
"from": os.Getenv("HTTPSMS_FROM"),
105+
"to": os.Getenv("HTTPSMS_TO"),
106+
"encrypted": false,
107+
})
108+
if err != nil {
109+
log.Fatal(stacktrace.Propagate(err, "cannot marshal payload"))
110+
}
111+
112+
req, err := http.NewRequest(http.MethodGet, "https://api.httpsms.com/v1/messages/send", bytes.NewBuffer(payload))
113+
if err != nil {
114+
log.Fatal(stacktrace.Propagate(err, "cannot create request"))
115+
}
116+
117+
req.Header.Add("x-api-key", os.Getenv("HTTPSMS_KEY"))
118+
119+
res, err := http.DefaultClient.Do(req)
120+
if err != nil {
121+
log.Fatal(stacktrace.Propagate(err, "cannot send request"))
122+
}
123+
124+
fmt.Printf("client: got response!\n")
125+
fmt.Printf("client: status code: %d\n", res.StatusCode)
126+
127+
resBody, err := io.ReadAll(res.Body)
128+
if err != nil {
129+
log.Fatal(stacktrace.Propagate(err, "could not read response body"))
130+
}
131+
132+
fmt.Printf("client: response body: %s\n", resBody)
133+
}
134+
95135
func sendSMS(content string) {
96136
var response string
97137
err := requests.URL(os.Getenv("BASIC_URL")).

0 commit comments

Comments
 (0)