Skip to content

Instantly share code, notes, and snippets.

@jlsherrill
Created July 20, 2023 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlsherrill/d07efa70bed152d8428c758b7332f95e to your computer and use it in GitHub Desktop.
Save jlsherrill/d07efa70bed152d8428c758b7332f95e to your computer and use it in GitHub Desktop.
go file to hammer a content-sources with requests
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"sync"
"github.com/content-services/content-sources-backend/pkg/config"
"github.com/content-services/content-sources-backend/pkg/db"
uuid2 "github.com/google/uuid"
)
func main() {
config.Load()
config.ConfigureLogging()
err := db.Connect()
if err != nil {
panic(err)
}
defer db.Close()
count := 1000
wg := sync.WaitGroup{}
wg.Add(count)
for i := 0; i < count; i++ {
go func() {
name := uuid2.NewString()
url := "http://example.com/" + uuid2.NewString() + "/"
postBody, _ := json.Marshal(map[string]string{
"name": name,
"url": url,
})
client := &http.Client{}
requestBody := bytes.NewBuffer(postBody)
req, err := http.NewRequest("POST", "http://localhost:8000/api/content-sources/v1.0/repositories/", requestBody)
if err != nil {
fmt.Println("ERROR creating request")
panic(-1)
}
req.Header.Add("x-rh-identity", "eyJpZGVudGl0eSI6eyJ0eXBlIjoiVXNlciIsInVzZXIiOnsidXNlcm5hbWUiOiJqZG9lIn0sImludGVybmFsIjp7Im9yZ19pZCI6IjEyMyJ9fX0K")
req.Header.Add("Content-Type", "application/json")
fmt.Printf("Starting request")
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
fmt.Printf("Request error, %v\n", "FOO")
} else {
fmt.Printf("DONE: %v\n", resp.Status)
}
wg.Done()
}()
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment