Skip to content

Commit 8df3345

Browse files
committed
feat: main function of the application
1 parent ca956ac commit 8df3345

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"github.com/DanielFillol/DataJUD_API_CALLER/csv"
5+
"github.com/DanielFillol/DataJUD_API_CALLER/request"
6+
"log"
7+
"time"
8+
)
9+
10+
const (
11+
BASE = "https://api-publica.datajud.cnj.jus.br/api_publica_"
12+
AUTH = "APIKey cDZHYzlZa0JadVREZDJCendQbXY6SkJlTzNjLV9TRENyQk1RdnFKZGRQdw=="
13+
METHOD = "POST"
14+
WORKERS = 1
15+
FILENAME = "response"
16+
FOLDER = "data"
17+
FILEPATH = "data/requests.csv"
18+
SEPARATOR = ','
19+
HEADER = true
20+
)
21+
22+
func main() {
23+
// Load data to be requested from CSV file
24+
requests, err := csv.Read(FILEPATH, SEPARATOR, HEADER)
25+
if err != nil {
26+
log.Fatal("Error loading requests from CSV: ", err)
27+
}
28+
29+
// Make API requests asynchronously
30+
start := time.Now()
31+
log.Println("Starting API calls...")
32+
33+
results, err := request.AsyncAPIRequest(requests, WORKERS, BASE, METHOD, AUTH)
34+
if err != nil {
35+
log.Println("Error making API requests: ", err)
36+
}
37+
log.Println("Finished API calls in ", time.Since(start))
38+
39+
// Write API response to CSV file
40+
err = csv.Write(FILENAME, FOLDER, results)
41+
if err != nil {
42+
log.Fatal("Error writing API response to CSV: ", err)
43+
}
44+
}

0 commit comments

Comments
 (0)