35 lines
936 B
Go
35 lines
936 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/api"
|
|
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/database"
|
|
)
|
|
|
|
var (
|
|
connectionString = ""
|
|
port = ":8080"
|
|
)
|
|
|
|
const (
|
|
curlhelp = `curl -X POST localhost:8080/api/products -d '{ "products": { "A6053": 2, "B3009": 1200 }, "context": { "country": "EU", "state": "" } }'`
|
|
)
|
|
|
|
func main() {
|
|
connectionString := os.Getenv("CONNECTIONSTRING")
|
|
nps := database.NewProductService(connectionString)
|
|
if len(connectionString) == 0 {
|
|
fmt.Println("Connectionstring fehlt!. Bsp.: <user>:<passwort>@tcp(127.0.0.1:3306)/elio?parseTime=true")
|
|
return
|
|
}
|
|
//Dependency Injection
|
|
http.HandleFunc("/api/products", api.GetProductApiHandleFunc(nps))
|
|
log.Printf("Easy Peasy: Die Party startet auf Port %s\n", port)
|
|
log.Printf("Probiers mal damit: %s\n", curlhelp)
|
|
log.Fatal(http.ListenAndServe(port, nil))
|
|
}
|