Files
DHL-Tracker-GO/main.go
Valentijn van der Jagt 6fa9ba0057 freaking-dell speciaal
2026-03-10 08:33:39 +01:00

89 lines
2.0 KiB
Go

package main
/*
Author: Valentijn van der Jagt
In this project i play around with go. This is my first time writing go, and im using a lot of help from sources. all useful sources are listed in the comments below.
*/
// https://stackoverflow.com/questions/61080317/go-lang-very-simple-http-post-requests-and-response-endpoint, HTTP Server example
// https://stackoverflow.com/questions/16466320/is-there-a-way-to-do-repetitive-tasks-at-intervals, How timer intervals work in GoLang
// https://pkg.go.dev/modernc.org/sqlite#section-documentation, how to interface with specifically sqlite in GoLang
// https://github.com/mattn/go-sqlite3/blob/v1.14.34/_example/simple/simple.go, How to inferface with a database in GoLang.
// https://go.dev/tour/moretypes/6, arrays....
// https://go.dev/doc/tutorial/handle-errors, deal with returning errors
import (
"database/sql"
"log"
"errors"
_ "modernc.org/sqlite"
)
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
if (success){
return v, nil
}
}
return "", errors.New("Parcel not found in the common providers!")
}
func markPackageSubscription(code string, postal_code string, service string){
/*
{
"type": "Shipment",
"format": "Default",
"service": "parcel-nl",
"hook": {
"uri": "https://your-server.example.com/dhl-webhook"
},
"events": [
"pre-transit",
"transit",
"delivered",
"failure",
"unknown"
],
"shipmentIDsWithChallengeDetails": [
{
"shipmentID": "3SABCDEF123456",
"postalCode": "1012AB"
}
]
}
*/
}
func main() {
db, err := sql.Open("sqlite", "./dhl.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
code := "blablbla"
postal := "1234ab"
provider, err := findParcelProvider(code, postal)
if (err != nil){
log.Fatal(err)
}
// if theres a result, print it.
log.Printf("Code: %s, Postal Code: %s, Tracking Service: %s", code, postal, provider)
}