Open GoogleCodeExporter opened 9 years ago
I have the obvious patch for this. But it will break the API of this client. Is
that ok?
Original comment by ago...@google.com
on 30 Nov 2012 at 5:37
# HG changeset patch
# User Adam Goode <agoode@google.com>
# Date 1354684256 18000
# Node ID 4e26f8e050b6aa8abc9a417c1aac886670412cb5
# Parent 2253ff9f7a543f13da7119aaba26932f443d613d
Use *time.Time for fields instead of plain string when format is date or
date-time
diff -r 2253ff9f7a54 -r 4e26f8e050b6 examples/tasks.go
--- a/examples/tasks.go Mon Nov 26 17:35:03 2012 -0800
+++ b/examples/tasks.go Wed Dec 05 00:10:56 2012 -0500
@@ -3,6 +3,7 @@
import (
"log"
"net/http"
+ "time"
tasks "code.google.com/p/google-api-go-client/tasks/v1"
)
@@ -13,10 +14,11 @@
func tasksMain(client *http.Client, argv []string) {
taskapi, _ := tasks.New(client)
+ due := time.Date(2011, time.October, 15, 12, 00, 00, 000, time.UTC)
task, err := taskapi.Tasks.Insert("@default", &tasks.Task{
Title: "finish this API code generator thing",
Notes: "ummmm",
- Due: "2011-10-15T12:00:00.000Z",
+ Due: &due,
}).Do()
log.Printf("Got task, err: %#v, %v", task, err)
}
diff -r 2253ff9f7a54 -r 4e26f8e050b6 google-api-go-generator/gen.go
--- a/google-api-go-generator/gen.go Mon Nov 26 17:35:03 2012 -0800
+++ b/google-api-go-generator/gen.go Wed Dec 05 00:10:56 2012 -0500
@@ -26,7 +26,7 @@
)
// goGenVersion is the version of the Go code generator
-const goGenVersion = "0.5"
+const goGenVersion = "0.6"
var (
apiToGenerate = flag.String("api", "*", "The API ID to generate, like 'tasks:v1'. A value of '*' means all.")
@@ -361,6 +361,7 @@
"net/url",
"strconv",
"strings",
+ "time",
} {
p("\t%q\n", pkg)
}
@@ -373,6 +374,7 @@
pn("var _ = url.Parse")
pn("var _ = googleapi.Version")
pn("var _ = errors.New")
+ pn("var _ = time.Now")
pn("")
pn("const apiId = %q", jstr(m, "id"))
pn("const apiName = %q", jstr(m, "name"))
@@ -1317,6 +1319,8 @@
switch format {
case "int64", "uint64", "int32", "uint32":
gotype = format
+ case "date", "date-time":
+ gotype = "*time.Time"
}
case "number":
gotype = "float64"
Original comment by ago...@google.com
on 5 Dec 2012 at 5:12
Actually, this is invalid, since it seems like Google will generate and accept
non-RFC3339 dates (outside of the year range 0000-9999). So a custom marshaller
will be required.
Original comment by ago...@google.com
on 11 Dec 2012 at 5:04
Perhaps the correct solution is to fix Go:
https://code.google.com/p/go/issues/detail?id=4556
Original comment by ago...@google.com
on 16 Dec 2012 at 4:44
I have a solution that adds googleapi.Time.
Original comment by ago...@google.com
on 18 Dec 2012 at 5:22
*time.Time is weird. time.Time would be the proper type.
But I'm concerned about changing this... it would break all existing callers.
I don't know how many that is.
Original comment by bradfitz@google.com
on 18 Dec 2012 at 6:36
*time.Time is weird, but omitIfEmpty doesn't work on plain time.Time.
Original comment by ago...@google.com
on 18 Dec 2012 at 6:40
Sorry, I meant "omitempty", as in `json:"modifiedTime,omitempty"`
Original comment by ago...@google.com
on 18 Dec 2012 at 6:41
The other solution is to leave at string, so that omitempty works, and callers
don't have to change, but provide parse/unparse in googleapi for the particular
time format that Google APIs require (both in sending and receiving).
package googleapi
func ParseTime(s string) (time.Time, err)
func FormatTime(t time.Time) err
Original comment by ago...@google.com
on 19 Dec 2012 at 2:35
oops I mean
FormatTime(t time.Time) string
Original comment by ago...@google.com
on 19 Dec 2012 at 2:35
Original issue reported on code.google.com by
ago...@google.com
on 30 Nov 2012 at 4:49