From 481bdf346af4bc5946caf87c32cc64ab5f720933 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 4 Jun 2013 19:05:30 +0200 Subject: [PATCH] blobref: enforce Go1.1 is required, also types: rm Go1.0 RFC3339Nanos work-around Change-Id: I9ce8495927fe349e7882f0a7d6c4f0051693fa2c --- pkg/blobref/check_go_version.go | 5 ++++ pkg/types/types.go | 49 ++++++--------------------------- 2 files changed, 13 insertions(+), 41 deletions(-) create mode 100644 pkg/blobref/check_go_version.go diff --git a/pkg/blobref/check_go_version.go b/pkg/blobref/check_go_version.go new file mode 100644 index 000000000..6f1a2a124 --- /dev/null +++ b/pkg/blobref/check_go_version.go @@ -0,0 +1,5 @@ +// +build !go1.1 + +package blobref + +Sorry, Camlistore requires Go 1.1. diff --git a/pkg/types/types.go b/pkg/types/types.go index c304fdfc5..e887bf366 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -21,13 +21,11 @@ import ( "fmt" "regexp" "runtime" - "strings" "time" ) var ( goVersion = runtime.Version() - isGo10 = goVersion == "go1" || strings.HasPrefix(runtime.Version(), "go1.0") dotNumbers = regexp.MustCompile(`\.\d+`) ) @@ -40,7 +38,6 @@ var ( _ json.Unmarshaler = (*Time3339)(nil) ) - func (t Time3339) String() string { return time.Time(t).UTC().Format(time.RFC3339Nano) } @@ -49,65 +46,35 @@ func (t Time3339) MarshalJSON() ([]byte, error) { return json.Marshal(t.String()) } -func parseForGo10(s string) (time.Time, error) { - var numbers string - noNanos := dotNumbers.ReplaceAllStringFunc(s, func(m string) string { - numbers = m - return "" - }) - t, err := time.Parse(time.RFC3339, noNanos) - if err != nil { - return t, fmt.Errorf("Failed to parse %q as an RFC 3339 time: %v", noNanos, err) - } - if numbers != "" { - nanos, err := time.ParseDuration(numbers + "s") - if err != nil { - return t, fmt.Errorf("Failed to parse %q as a duration: %v", numbers+"s", err) - } - t = t.Add(nanos) - } - return t, nil -} - func (t *Time3339) UnmarshalJSON(b []byte) error { if len(b) < 2 || b[0] != '"' || b[len(b)-1] != '"' { return fmt.Errorf("types: failed to unmarshal non-string value %q as an RFC 3339 time") } - tm, err := ParseTime3339(string(b[1 : len(b)-1])) + tm, err := time.Parse(time.RFC3339Nano, string(b[1:len(b)-1])) if err != nil { return err } - *t = tm + *t = Time3339(tm) return nil } -// ParseTime3339 parses a string in RFC3339 format. -func ParseTime3339(v string) (t Time3339, err error) { - var tm time.Time - if isGo10 { - tm, err = parseForGo10(v) - } else { - tm, err = time.Parse(time.RFC3339Nano, v) - } - return Time3339(tm), err -} - -// ParseTime3339 parses a string in RFC3339 format. If it's invalid, +// ParseTime3339OrZero parses a string in RFC3339 format. If it's invalid, // the zero time value is returned instead. func ParseTime3339OrZero(v string) Time3339 { - t, err := ParseTime3339(v) + t, err := time.Parse(time.RFC3339Nano, v) if err != nil { return Time3339{} } - return t + return Time3339(t) } func ParseTime3339OrZil(v string) *Time3339 { - t, err := ParseTime3339(v) + t, err := time.Parse(time.RFC3339Nano, v) if err != nil { return nil } - return &t + tm := Time3339(t) + return &tm } // Time returns the time as a time.Time with slightly less stutter