diff --git a/ORM.go b/ORM.go index 6af6996..41e464e 100644 --- a/ORM.go +++ b/ORM.go @@ -6,7 +6,7 @@ import ( _ "github.com/lib/pq" ) -func main() { +func mainORM() { connStr := "user=ada password='TR42ma31&*' dbname=dbada sslmode=disable" db, err := sql.Open("postgres", connStr) if err != nil { diff --git a/httpListener b/httpListener new file mode 100755 index 0000000..157aa3e Binary files /dev/null and b/httpListener differ diff --git a/httpListener.go b/httpListener.go index 529c394..fd548b0 100644 --- a/httpListener.go +++ b/httpListener.go @@ -5,24 +5,29 @@ import ( "fmt" "net/http" "log" + "io/ioutil" ) type Data struct { - identifier string - password string + Identifier string + Password string } func handleRequest(w http.ResponseWriter, r *http.Request) { - var data Data - err := json.NewDecoder(r.Body).Decode(&data) + body, err := ioutil.ReadAll(r.Body) if err != nil { - http.Error(w,err.Error(), http.StatusBadRequest) - return + fmt.Printf("body read KO") } - fmt.Fprintf(w, "Data: %+v", data) + var data Data + err = json.Unmarshal(body, &data) + if err != nil { + fmt.Printf("deserialis KO") + } + fmt.Printf("%+v\n", data) } func main() { + mainORM() http.HandleFunc("/", handleRequest) log.Fatal(http.ListenAndServe(":8088", nil)) } diff --git a/jsonEmitter.go b/jsonEmitter.go.poc similarity index 75% rename from jsonEmitter.go rename to jsonEmitter.go.poc index efc0254..146cffb 100644 --- a/jsonEmitter.go +++ b/jsonEmitter.go.poc @@ -9,33 +9,36 @@ import ( ) type Data struct { - identifier string - password string + Identifier string + Password string } func main() { url := "http://localhost:8088" // Remplacez par l'URL de votre choix data := Data { - identifier: "machevaldo", - password: "superPassword"} + Identifier: "machevaldo", + Password: "superPassword"} jsonData, err := json.Marshal(data) if err != nil { log.Fatal(err) } - + var m Data + err1 := json.Unmarshal(jsonData, &m) + if err1 != nil { + log.Fatal(err) + } + fmt.Println(m) req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) if err != nil { log.Fatal(err) } req.Header.Set("Content-Type", "application/json") - client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() - fmt.Println("Response Status:", resp.Status) }