summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-openapi/strfmt
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-openapi/strfmt')
-rw-r--r--vendor/github.com/go-openapi/strfmt/.golangci.yml6
-rw-r--r--vendor/github.com/go-openapi/strfmt/README.md13
-rw-r--r--vendor/github.com/go-openapi/strfmt/date.go29
-rw-r--r--vendor/github.com/go-openapi/strfmt/go.mod2
-rw-r--r--vendor/github.com/go-openapi/strfmt/time.go90
5 files changed, 125 insertions, 15 deletions
diff --git a/vendor/github.com/go-openapi/strfmt/.golangci.yml b/vendor/github.com/go-openapi/strfmt/.golangci.yml
index f260ce7e5c..03ffa31a4e 100644
--- a/vendor/github.com/go-openapi/strfmt/.golangci.yml
+++ b/vendor/github.com/go-openapi/strfmt/.golangci.yml
@@ -20,6 +20,11 @@ linters:
- lll
- gochecknoinits
- gochecknoglobals
+ - godox
+ - gocognit
+ - whitespace
+ - wsl
+ - funlen
issues:
exclude-rules:
@@ -27,4 +32,5 @@ issues:
text: "should be .*ObjectID"
linters:
- golint
+ - stylecheck
diff --git a/vendor/github.com/go-openapi/strfmt/README.md b/vendor/github.com/go-openapi/strfmt/README.md
index 87357cd024..b2645ce18a 100644
--- a/vendor/github.com/go-openapi/strfmt/README.md
+++ b/vendor/github.com/go-openapi/strfmt/README.md
@@ -43,6 +43,19 @@ It also provides convenient extensions to go-openapi users.
> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
> "integer" (e.g. float, double, int32...).
+## Type conversion
+
+All types defined here are stringers and may be converted to strings with `.String()`.
+Note that most types defined by this package may be converted directly to string like `string(Email{})`.
+
+`Date` and `DateTime` may be converted directly to `time.Time` like `time.Time(Time{})`.
+Similarly, you can convert `Duration` to `time.Duration` as in `time.Duration(Duration{})`
+
+## Using pointers
+
+The `conv` subpackage provides helpers to convert the types to and from pointers, just like `go-openapi/swag` does
+with primitive types.
+
## Format types
Types defined in strfmt expose marshaling and validation capabilities.
diff --git a/vendor/github.com/go-openapi/strfmt/date.go b/vendor/github.com/go-openapi/strfmt/date.go
index 2959e65730..15029ffa2f 100644
--- a/vendor/github.com/go-openapi/strfmt/date.go
+++ b/vendor/github.com/go-openapi/strfmt/date.go
@@ -151,3 +151,32 @@ func (d *Date) DeepCopy() *Date {
d.DeepCopyInto(out)
return out
}
+
+// GobEncode implements the gob.GobEncoder interface.
+func (d Date) GobEncode() ([]byte, error) {
+ return d.MarshalBinary()
+}
+
+// GobDecode implements the gob.GobDecoder interface.
+func (d *Date) GobDecode(data []byte) error {
+ return d.UnmarshalBinary(data)
+}
+
+// MarshalBinary implements the encoding.BinaryMarshaler interface.
+func (d Date) MarshalBinary() ([]byte, error) {
+ return time.Time(d).MarshalBinary()
+}
+
+// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
+func (d *Date) UnmarshalBinary(data []byte) error {
+ var original time.Time
+
+ err := original.UnmarshalBinary(data)
+ if err != nil {
+ return err
+ }
+
+ *d = Date(original)
+
+ return nil
+}
diff --git a/vendor/github.com/go-openapi/strfmt/go.mod b/vendor/github.com/go-openapi/strfmt/go.mod
index 78c8489b20..eaf7544712 100644
--- a/vendor/github.com/go-openapi/strfmt/go.mod
+++ b/vendor/github.com/go-openapi/strfmt/go.mod
@@ -11,3 +11,5 @@ require (
github.com/tidwall/pretty v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.0.3
)
+
+go 1.13
diff --git a/vendor/github.com/go-openapi/strfmt/time.go b/vendor/github.com/go-openapi/strfmt/time.go
index f9151259ed..0b2f52d249 100644
--- a/vendor/github.com/go-openapi/strfmt/time.go
+++ b/vendor/github.com/go-openapi/strfmt/time.go
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,14 +16,16 @@ package strfmt
import (
"database/sql/driver"
+ "encoding/binary"
"encoding/json"
- "errors"
"fmt"
"regexp"
"strings"
"time"
"go.mongodb.org/mongo-driver/bson"
+
+ "go.mongodb.org/mongo-driver/bson/bsontype"
)
func init() {
@@ -57,12 +59,16 @@ const (
RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
// ISO8601LocalTime represents a ISO8601 format to ISO8601 in local time (no timezone)
ISO8601LocalTime = "2006-01-02T15:04:05"
+ // ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision (dropped secs)
+ ISO8601TimeWithReducedPrecision = "2006-01-02T15:04Z"
+ // ISO8601TimeWithReducedPrecision represents a ISO8601 format with reduced precision and no timezone (dropped seconds + no timezone)
+ ISO8601TimeWithReducedPrecisionLocaltime = "2006-01-02T15:04"
// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`
)
var (
- dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime}
+ dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano, ISO8601LocalTime, ISO8601TimeWithReducedPrecision, ISO8601TimeWithReducedPrecisionLocaltime}
rxDateTime = regexp.MustCompile(DateTimePattern)
// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
MarshalFormat = RFC3339Millis
@@ -165,26 +171,51 @@ func (t *DateTime) UnmarshalJSON(data []byte) error {
return nil
}
+// MarshalBSON renders the DateTime as a BSON document
func (t DateTime) MarshalBSON() ([]byte, error) {
- return bson.Marshal(bson.M{"data": t.String()})
+ return bson.Marshal(bson.M{"data": t})
}
+// UnmarshalBSON reads the DateTime from a BSON document
func (t *DateTime) UnmarshalBSON(data []byte) error {
- var m bson.M
- if err := bson.Unmarshal(data, &m); err != nil {
- return err
+ var obj struct {
+ Data DateTime
}
- if data, ok := m["data"].(string); ok {
- rd, err := ParseDateTime(data)
- if err != nil {
- return err
- }
- *t = rd
- return nil
+ if err := bson.Unmarshal(data, &obj); err != nil {
+ return err
}
- return errors.New("couldn't unmarshal bson bytes value as Date")
+ *t = obj.Data
+
+ return nil
+}
+
+// MarshalBSONValue is an interface implemented by types that can marshal themselves
+// into a BSON document represented as bytes. The bytes returned must be a valid
+// BSON document if the error is nil.
+// Marshals a DateTime as a bsontype.DateTime, an int64 representing
+// milliseconds since epoch.
+func (t DateTime) MarshalBSONValue() (bsontype.Type, []byte, error) {
+ // UnixNano cannot be used, the result of calling UnixNano on the zero
+ // Time is undefined.
+ i64 := time.Time(t).Unix() * 1000
+ buf := make([]byte, 8)
+ binary.LittleEndian.PutUint64(buf, uint64(i64))
+
+ return bsontype.DateTime, buf, nil
+}
+
+// UnmarshalBSONValue is an interface implemented by types that can unmarshal a
+// BSON value representation of themselves. The BSON bytes and type can be
+// assumed to be valid. UnmarshalBSONValue must copy the BSON value bytes if it
+// wishes to retain the data after returning.
+func (t *DateTime) UnmarshalBSONValue(tpe bsontype.Type, data []byte) error {
+ i64 := int64(binary.LittleEndian.Uint64(data))
+ // TODO: Use bsonprim.DateTime.Time() method
+ *t = DateTime(time.Unix(i64/1000, i64%1000*1000000))
+
+ return nil
}
// DeepCopyInto copies the receiver and writes its value into out.
@@ -201,3 +232,32 @@ func (t *DateTime) DeepCopy() *DateTime {
t.DeepCopyInto(out)
return out
}
+
+// GobEncode implements the gob.GobEncoder interface.
+func (t DateTime) GobEncode() ([]byte, error) {
+ return t.MarshalBinary()
+}
+
+// GobDecode implements the gob.GobDecoder interface.
+func (t *DateTime) GobDecode(data []byte) error {
+ return t.UnmarshalBinary(data)
+}
+
+// MarshalBinary implements the encoding.BinaryMarshaler interface.
+func (t DateTime) MarshalBinary() ([]byte, error) {
+ return time.Time(t).MarshalBinary()
+}
+
+// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
+func (t *DateTime) UnmarshalBinary(data []byte) error {
+ var original time.Time
+
+ err := original.UnmarshalBinary(data)
+ if err != nil {
+ return err
+ }
+
+ *t = DateTime(original)
+
+ return nil
+}