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

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
DHL_API_KEY = "...."
DHL_API_SECRET = "...."

1
go.mod
View File

@@ -7,6 +7,7 @@ require modernc.org/sqlite v1.46.1
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect

2
go.sum
View File

@@ -6,6 +6,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=

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)
}