http testing & dotenv experimentation

This commit is contained in:
Valentijn van der Jagt
2026-03-10 08:49:28 +01:00
parent 6fa9ba0057
commit ca66bafe72
4 changed files with 35 additions and 1 deletions

31
main.go
View File

@@ -18,16 +18,23 @@ import (
"database/sql"
"log"
"errors"
"net/http"
"io"
"os"
"github.com/joho/godotenv"
_ "modernc.org/sqlite"
)
const API_URL string = "http://www.google.com/robots.txt"
var dhl_api_key string
func findParcelProvider(code string, postal_code string)(string, error){
providers := [4]string{"express", "parcel-nl", "ecommerce", "ecommerce-europe"}
for _, v := range providers {
// do http api reqiest
success := false
success := true
if (success){
return v, nil
@@ -62,11 +69,32 @@ func markPackageSubscription(code string, postal_code string, service string){
}
*/
res, err := http.Get(API_URL)
if err != nil {
log.Fatal(err)
}
body, err := io.ReadAll(res.Body)
res.Body.Close()
if res.StatusCode > 299 {
log.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body)
}
if err != nil {
log.Fatal(err)
}
log.Printf("%s, %s\n", body, dhl_api_key)
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
dhl_api_key = os.Getenv("DHL_API_KEY")
db, err := sql.Open("sqlite", "./dhl.db")
if err != nil {
log.Fatal(err)
@@ -85,4 +113,5 @@ func main() {
// if theres a result, print it.
log.Printf("Code: %s, Postal Code: %s, Tracking Service: %s", code, postal, provider)
markPackageSubscription(code, postal, provider)
}