I am trying to parse a timestamp that is generated in python and posted over to here to be stored in cassandra and I am getting a weird error.
parsing time ""2015-11-05 14:14:32-0700"" as ""2006-01-02T15:04:05Z07:00"": cannot parse " 14:14:32-0700"" as "T"
I don't want to modify the time given to me from the python in anyway, just want to pass it right into cassandra but the driver says I need to have it be time.Time
(not string) to do so.
Here is the code
type OurCustomType struct {
TimeStamp time.Time `json:"timestamp"`
}
func extractJsonBody(r *http.Request) []byte {
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
if err != nil {
//...
}
if err := r.Body.Close(); err != nil {
//....
}
return body
}
func View(w http.ResponseWriter, r *http.Request) {
var variable OurCustomType
body := extractJsonBody(r)
if err := json.Unmarshal(body, &variable); err != nil {
//..
} else {
//...
}
}
Edit: I have implemented my own time.Time
type and implemented a custom UnmarshalJSON
to attempt to fix this issue.
type PythonTime struct {
time.Time
}
func (self *PythonTime) UnmarshalJSON(b []byte) (err error) {
self.Time, err = time.Parse("2006-01-02 15:04:05-0700", string(b))
return
}
But I am not getting this error:
parsing time ""2015-11-05 14:14:32-0700"" as "2006-01-02 15:04:05-0700": cannot parse ""2015-11-05 14:14:32-0700"" as "2006"