diff --git a/cmd/callWorker.go b/cmd/callWorker.go new file mode 100644 index 0000000..4c9d7d3 --- /dev/null +++ b/cmd/callWorker.go @@ -0,0 +1,40 @@ +package main + +import ( + "time" +) + +type forceData struct { + worker int + wordList string + url string +} + +func executeQueryFromFile(data forceData, currentPath chan string) { + for taskData := range currentPath{ + queryExecute(data, taskData, "POST") + } +} + +func mainRequest(data forceData) { + channel := make(chan string) + wordArray := GetFileContent("../wordList/rootList") + + for i := 0 ;i < data.worker; i++ { + go executeQueryFromFile(data, channel) + } + for i := 0; i < len(wordArray); i++ { + channel <- wordArray[i] + } + time.Sleep(1 * time.Second) + close(channel) +} + +func main () { + data := forceData { + worker: 3, + wordList: "../wordList/rootList", + url: "http://localhost:3333", + } + mainRequest(data); +} \ No newline at end of file diff --git a/cmd/getFile.go b/cmd/getFile.go new file mode 100644 index 0000000..7accbb0 --- /dev/null +++ b/cmd/getFile.go @@ -0,0 +1,18 @@ +package main + +import ( + "os" + "fmt" + "log" + "strings" +) + +func GetFileContent(filePath string) []string{ + body, err := os.ReadFile(filePath) + if err != nil { + log.Fatalf("unable to read file: %v", err) + } + dataTab := strings.Split(string(body), "\n") + fmt.Println(dataTab[0]) + return dataTab +} \ No newline at end of file diff --git a/cmd/queryExecute.go b/cmd/queryExecute.go new file mode 100644 index 0000000..42b7021 --- /dev/null +++ b/cmd/queryExecute.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "log" + "io/ioutil" + "net/http" +) + +func queryExecute(data forceData, path string, method string) { + + client := &http.Client{} + req, err := http.NewRequest(method, data.url + path, nil) + if err != nil { + log.Fatal(err) + } + + q := req.URL.Query() + + req.URL.RawQuery = q.Encode() + + resp, err := client.Do(req) + if err != nil { + fmt.Println(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(body)) + } \ No newline at end of file diff --git a/src/query/callWorker.go b/src/query/callWorker.go new file mode 100644 index 0000000..1a5b24b --- /dev/null +++ b/src/query/callWorker.go @@ -0,0 +1,32 @@ +package main + +import ( + "time" +) + +type forceData struct { + worker int + wordList string + url string +} + +func executeQueryFromFile(data forceData, currentPath chan string) { + for taskData := range currentPath{ + queryExecute(data, taskData, "POST") + } +} + +func mainRequest(data forceData) { + channel := make(chan string) + wordArray := GetFileContent("../wordList/rootList") + + for i := 0 ;i < data.worker; i++ { + go executeQueryFromFile(data, channel) + } + for i := 0; i < len(wordArray); i++ { + channel <- wordArray[i] + } + time.Sleep(1 * time.Second) + close(channel) +} + diff --git a/src/query/queryExecute.go b/src/query/queryExecute.go new file mode 100644 index 0000000..42b7021 --- /dev/null +++ b/src/query/queryExecute.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "log" + "io/ioutil" + "net/http" +) + +func queryExecute(data forceData, path string, method string) { + + client := &http.Client{} + req, err := http.NewRequest(method, data.url + path, nil) + if err != nil { + log.Fatal(err) + } + + q := req.URL.Query() + + req.URL.RawQuery = q.Encode() + + resp, err := client.Do(req) + if err != nil { + fmt.Println(err) + } + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(body)) + } \ No newline at end of file diff --git a/src/utils/getFile.go b/src/utils/getFile.go new file mode 100644 index 0000000..7accbb0 --- /dev/null +++ b/src/utils/getFile.go @@ -0,0 +1,18 @@ +package main + +import ( + "os" + "fmt" + "log" + "strings" +) + +func GetFileContent(filePath string) []string{ + body, err := os.ReadFile(filePath) + if err != nil { + log.Fatalf("unable to read file: %v", err) + } + dataTab := strings.Split(string(body), "\n") + fmt.Println(dataTab[0]) + return dataTab +} \ No newline at end of file