Here is the date that i send (in raw text) mode from a jsonified models.DateTimeField :
2019-05-07 16:49:47.351628+00:00
How i receive it in golang :
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/lib/pq"
)
type DataLink struct {
Created pq.NullTime `json:"created"`
}
type SendData struct {
Name string `json:"Name"`
}
func main() {
var reception = DataLink{}
var sendData = SendData{}
sendData.Name = "Melon"
url := "http://127.0.0.1:8309/getLinks/"
fmt.Println("URL:>", url)
js, err := json.Marshal(sendData)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(js))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
//fmt.Println("response Status:", resp.Status)
//fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
//fmt.Println("response Body:", string(body))
err = json.Unmarshal(body, &reception)
fmt.Println(reception.Created)
}
But when i print my object i have a :
{0001-01-01 00:00:00 +0000 UTC false}
How to convert ideally from a django time field or with string manipulation my date time to make it compatible with go and pq.NullTime ?
Everything else works (bool, int, float , string) but not the date ...