Update a few dependencies

github.com/go-openapi/*
github.com/asaskevich/govalidator
This commit is contained in:
Mikhail Mazurskiy
2018-10-18 23:33:10 +11:00
parent b8731a76f0
commit 8763223ab9
191 changed files with 18648 additions and 1800 deletions

View File

@@ -1 +0,0 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.Mlxfs4BKn_738Q2qrkcYie9JMBntqK9AMMBknZ5CzzxxUbhWO7MCRNfgBDULzlMpxrmSkHERZAYPv3Drw7M25RxvgCIX1YQrQi2NB8vGHJm7VwcyfWw9nyGiIRe7QSwZUZYoUpZlJh6uiShl8PHFrN4tOG8Jusn2XekrOGTNMHxa6jD5mqzD2vRw0fqKU9MTc4ZcMr-B3qCJ20xcsrxvAGiHDwGonTOFDQZFblrWXnyXWPdYAXbDbzOLgZcBiswCCBz8w92Jw109yQbzEq8RxwzB0ooMHCwEGz3R_VK1_ZHY7Y9up820mucuINpxg427kiKl-Lg6tq1NKGLluWsI3Q.JIB35VoY0hmRi6k_.bM_bNg5gbwyeCnn1l7p1Gj2OoZbTXHRZ0LrfnT8Kiv3045hw4V0UmM0214BeYrMs2xpwMRcwwIz4_ClmZkwv7-Ua_CpBbkPM1l1SXO8WFhdTA3t0lHjujE5_n8q8OLgAHRh9z4drXO8L7KtJIqcvpO5iAs7oaImG_ZRH0SH5tBjo4YNhZjsPE4Kg377LR9aaBkOJAAVALm06AkuswELE-AziMzFIzGvmcA0eAljHtRFYBEE3s7IV-HDPdpk64jM51nFq7Wwqit7k7zKq3tNwJmsz8Tq4X_hYpUXGD3gPeqTyyATI6I2CUzhQQ7K-TP9j8H_aFZdb6bEAIuP98Zx0TSuiuR6z49Z9qb3RFbONfqwFQ-MGj_LAM_T8hwR1JhhY4lvfLGq9VJ1ZCQWEyUr-ghHk9NOfCv1Fm2UUR2NB7z6ykBVYWyowmjIPuG8WajtQqmNJ62vIxq7-dMqxw1f2FBMMKxucMPqxJSzJOkpfBgQLxI_Ipxt0LA0cB0GAnrnUf9yP7ANY8usq_SuP5Yt0JZ_jA6urAL_dQHt9p2sbyyqUXGr4KKvFnwAHlUnUnFT6NIFr-7h7CkbO-2dpa6RCWJsjAHUQjrrl7sRaKu9N-v76D3kbJpMX6JhT-tRgnnLQHVE.yidYXmedJrWMFBeFP6N-ZQ

View File

@@ -1,35 +0,0 @@
clone:
path: github.com/go-openapi/strfmt
matrix:
GO_VERSION:
- "1.6"
build:
integration:
image: golang:$$GO_VERSION
pull: true
commands:
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/pborman/uuid
- go get -u github.com/asaskevich/govalidator
- go get -u github.com/mailru/easyjson
- go get -u github.com/go-openapi/errors
- go test -race
- go test -v -cover -coverprofile=coverage.out -covermode=count ./...
notify:
slack:
channel: bots
webhook_url: $$SLACK_URL
username: drone
publish:
coverage:
server: https://coverage.vmware.run
token: $$GITHUB_TOKEN
# threshold: 70
# must_increase: true
when:
matrix:
GO_VERSION: "1.6"

26
vendor/github.com/go-openapi/strfmt/.editorconfig generated vendored Normal file
View File

@@ -0,0 +1,26 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
# Set default charset
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
charset = utf-8
# Tab indentation (no size specified)
[*.go]
indent_style = tab
[*.md]
trim_trailing_whitespace = false
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

19
vendor/github.com/go-openapi/strfmt/.golangci.yml generated vendored Normal file
View File

@@ -0,0 +1,19 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 25
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
linters:
enable-all: true
disable:
- maligned

View File

@@ -1,13 +0,0 @@
approve_by_comment: true
approve_regex: '^(:shipit:|:\+1:|\+1|LGTM|lgtm|Approved)'
reject_regex: ^[Rr]ejected
reset_on_push: false
reviewers:
members:
- casualjim
- chancez
- frapposelli
- vburenin
- pytlesk4
name: pullapprove
required: 1

20
vendor/github.com/go-openapi/strfmt/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,20 @@
after_success:
- bash <(curl -s https://codecov.io/bash)
go:
- '1.9'
- 1.10.x
- 1.11.x
install:
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/pborman/uuid
- go get -u github.com/asaskevich/govalidator
- go get -u github.com/mailru/easyjson
- go get -u github.com/go-openapi/errors
- go get -u github.com/mitchellh/mapstructure
- go get -u github.com/globalsign/mgo/bson
language: go
notifications:
slack:
secure: zE5AtIYTpYfQPnTzP+EaQPN7JKtfFAGv6PrJqoIZLOXa8B6zGb6+J1JRNNxWi7faWbyJOxa4FSSsuPsKZMycUK6wlLFIdhDxwqeo7Ew8r6rdZKdfUHQggfNS9wO79ARoNYUDHtmnaBUS+eWSM1YqSc4i99QxyyfuURLOeAaA/q14YbdlTlaw3lrZ0qT92ot1FnVGNOx064zuHtFeUf+jAVRMZ6Q3rvqllwIlPszE6rmHGXBt2VoJxRaBetdwd7FgkcYw9FPXKHhadwC7/75ZAdmxIukhxNMw4Tr5NuPcqNcnbYLenDP7B3lssGVIrP4BRSqekS1d/tqvdvnnFWHMwrNCkSnSc065G5+qWTlXKAemIclgiXXqE2furBNLm05MDdG8fn5epS0UNarkjD+zX336RiqwBlOX4KbF+vPyqcO98CsN0lnd+H6loc9reiTHs37orFFpQ+309av9be2GGsHUsRB9ssIyrewmhAccOmkRtr2dVTZJNFQwa5Kph5TNJuTjnZEwG/xUkEX2YSfwShOsb062JWiflV6PJdnl80pc9Tn7D5sO5Bf9DbijGRJwwP+YiiJtwtr+vsvS+n4sM0b5eqm4UoRo+JJO8ffoJtHS7ItuyRbVQCwEPJ4221WLcf5PquEEDdAPwR+K4Gj8qTXqTDdxOiES1xFUKVgmzhI=
script:
- ./hack/coverage

View File

@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"bson.go",
"date.go",
"default.go",
"doc.go",
@@ -15,9 +16,11 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/asaskevich/govalidator:go_default_library",
"//vendor/github.com/globalsign/mgo/bson:go_default_library",
"//vendor/github.com/go-openapi/errors:go_default_library",
"//vendor/github.com/mailru/easyjson/jlexer:go_default_library",
"//vendor/github.com/mailru/easyjson/jwriter:go_default_library",
"//vendor/github.com/mitchellh/mapstructure:go_default_library",
],
)

View File

@@ -1,5 +1,71 @@
# Strfmt [![Build Status](https://ci.vmware.run/api/badges/go-openapi/strfmt/status.svg)](https://ci.vmware.run/go-openapi/strfmt) [![Coverage](https://coverage.vmware.run/badges/go-openapi/strfmt/coverage.svg)](https://coverage.vmware.run/go-openapi/strfmt) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
# Strfmt [![Build Status](https://travis-ci.org/go-openapi/strfmt.svg?branch=master)](https://travis-ci.org/go-openapi/strfmt) [![codecov](https://codecov.io/gh/go-openapi/strfmt/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/strfmt) [![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/strfmt/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/strfmt?status.svg)](http://godoc.org/github.com/go-openapi/strfmt)
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/strfmt/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/go-openapi/strfmt?status.svg)](http://godoc.org/github.com/go-openapi/strfmt)
[![GolangCI](https://golangci.com/badges/github.com/go-openapi/strfmt.svg)](https://golangci.com)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/strfmt)](https://goreportcard.com/report/github.com/go-openapi/strfmt)
strfmt represents a well known string format such as credit card or email. The go toolkit for open api specifications knows how to deal with those.
This package exposes a registry of data types to support string formats in the go-openapi toolkit.
strfmt represents a well known string format such as credit card or email. The go toolkit for OpenAPI specifications knows how to deal with those.
## Supported data formats
go-openapi/strfmt follows the swagger 2.0 specification with the following formats
defined [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types).
It also provides convenient extensions to go-openapi users.
- [x] JSON-schema draft 4 formats
- date-time
- email
- hostname
- ipv4
- ipv6
- uri
- [x] swagger 2.0 format extensions
- binary
- byte (e.g. base64 encoded string)
- date (e.g. "1970-01-01")
- password
- [x] go-openapi custom format extensions
- bsonobjectid (BSON objectID)
- creditcard
- duration (e.g. "3 weeks", "1ms")
- hexcolor (e.g. "#FFFFFF")
- isbn, isbn10, isbn13
- mac (e.g "01:02:03:04:05:06")
- rgbcolor (e.g. "rgb(100,100,100)")
- ssn
- uuid, uuid3, uuid4, uuid5
> NOTE: as the name stands for, this package is intended to support string formatting only.
> It does not provide validation for numerical values with swagger format extension for JSON types "number" or
> "integer" (e.g. float, double, int32...).
## Format types
Types defined in strfmt expose marshaling and validation capabilities.
List of defined types:
- Base64
- CreditCard
- Date
- DateTime
- Duration
- Email
- HexColor
- Hostname
- IPv4
- IPv6
- ISBN
- ISBN10
- ISBN13
- MAC
- ObjectId
- Password
- RGBColor
- SSN
- URI
- UUID
- UUID3
- UUID4
- UUID5

127
vendor/github.com/go-openapi/strfmt/bson.go generated vendored Normal file
View File

@@ -0,0 +1,127 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// 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
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package strfmt
import (
"database/sql/driver"
"errors"
"fmt"
"github.com/globalsign/mgo/bson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
func init() {
var id ObjectId
// register this format in the default registry
Default.Add("bsonobjectid", &id, IsBSONObjectID)
}
// IsBSONObjectID returns true when the string is a valid BSON.ObjectId
func IsBSONObjectID(str string) bool {
return bson.IsObjectIdHex(str)
}
// ObjectId represents a BSON object ID (alias to github.com/globalsign/mgo/bson.ObjectId)
//
// swagger:strfmt bsonobjectid
type ObjectId bson.ObjectId
// NewObjectId creates a ObjectId from a Hex String
func NewObjectId(hex string) ObjectId {
return ObjectId(bson.ObjectIdHex(hex))
}
// MarshalText turns this instance into text
func (id *ObjectId) MarshalText() ([]byte, error) {
return []byte(bson.ObjectId(*id).Hex()), nil
}
// UnmarshalText hydrates this instance from text
func (id *ObjectId) UnmarshalText(data []byte) error { // validation is performed later on
*id = ObjectId(bson.ObjectIdHex(string(data)))
return nil
}
// Scan read a value from a database driver
func (id *ObjectId) Scan(raw interface{}) error {
var data []byte
switch v := raw.(type) {
case []byte:
data = v
case string:
data = []byte(v)
default:
return fmt.Errorf("cannot sql.Scan() strfmt.URI from: %#v", v)
}
return id.UnmarshalText(data)
}
// Value converts a value to a database driver value
func (id *ObjectId) Value() (driver.Value, error) {
return driver.Value(string(*id)), nil
}
func (id *ObjectId) String() string {
return string(*id)
}
// MarshalJSON returns the ObjectId as JSON
func (id *ObjectId) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
id.MarshalEasyJSON(&w)
return w.BuildBytes()
}
// MarshalEasyJSON writes the ObjectId to a easyjson.Writer
func (id *ObjectId) MarshalEasyJSON(w *jwriter.Writer) {
w.String(bson.ObjectId(*id).Hex())
}
// UnmarshalJSON sets the ObjectId from JSON
func (id *ObjectId) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
id.UnmarshalEasyJSON(&l)
return l.Error()
}
// UnmarshalEasyJSON sets the ObjectId from a easyjson.Lexer
func (id *ObjectId) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
*id = NewObjectId(data)
}
}
// GetBSON returns the hex representation of the ObjectId as a bson.M{} map.
func (id *ObjectId) GetBSON() (interface{}, error) {
return bson.M{"data": bson.ObjectId(*id).Hex()}, nil
}
// SetBSON sets the ObjectId from raw bson data
func (id *ObjectId) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
*id = NewObjectId(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as ObjectId")
}

View File

@@ -16,39 +16,31 @@ package strfmt
import (
"database/sql/driver"
"errors"
"fmt"
"regexp"
"time"
"github.com/globalsign/mgo/bson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
func init() {
d := Date{}
// register this format in the default registry
Default.Add("date", &d, IsDate)
}
// IsDate returns true when the string is a valid date
func IsDate(str string) bool {
matches := rxDate.FindAllStringSubmatch(str, -1)
if len(matches) == 0 || len(matches[0]) == 0 {
return false
}
m := matches[0]
return !(m[2] < "01" || m[2] > "12" || m[3] < "01" || m[3] > "31")
_, err := time.Parse(RFC3339FullDate, str)
return err == nil
}
const (
// RFC3339FullDate represents a full-date as specified by RFC3339
// See: http://goo.gl/xXOvVd
RFC3339FullDate = "2006-01-02"
// DatePattern pattern to match for the date format from http://tools.ietf.org/html/rfc3339#section-5.6
DatePattern = `^([0-9]{4})-([0-9]{2})-([0-9]{2})`
)
var (
rxDate = regexp.MustCompile(DatePattern)
)
// Date represents a date from the API
@@ -99,32 +91,60 @@ func (d *Date) Scan(raw interface{}) error {
// Value converts Date to a primitive value ready to written to a database.
func (d Date) Value() (driver.Value, error) {
return driver.Value(d), nil
return driver.Value(d.String()), nil
}
func (t Date) MarshalJSON() ([]byte, error) {
// MarshalJSON returns the Date as JSON
func (d Date) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
t.MarshalEasyJSON(&w)
d.MarshalEasyJSON(&w)
return w.BuildBytes()
}
func (t Date) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Time(t).Format(RFC3339FullDate))
// MarshalEasyJSON writes the Date to a easyjson.Writer
func (d Date) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Time(d).Format(RFC3339FullDate))
}
func (t *Date) UnmarshalJSON(data []byte) error {
// UnmarshalJSON sets the Date from JSON
func (d *Date) UnmarshalJSON(data []byte) error {
if string(data) == jsonNull {
return nil
}
l := jlexer.Lexer{Data: data}
t.UnmarshalEasyJSON(&l)
d.UnmarshalEasyJSON(&l)
return l.Error()
}
func (t *Date) UnmarshalEasyJSON(in *jlexer.Lexer) {
// UnmarshalEasyJSON sets the Date from a easyjson.Lexer
func (d *Date) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := time.Parse(RFC3339FullDate, data)
if err != nil {
in.AddError(err)
return
}
*t = Date(tt)
*d = Date(tt)
}
}
// GetBSON returns the Date as a bson.M{} map.
func (d *Date) GetBSON() (interface{}, error) {
return bson.M{"data": d.String()}, nil
}
// SetBSON sets the Date from raw bson data
func (d *Date) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
rd, err := time.Parse(RFC3339FullDate, data)
*d = Date(rd)
return err
}
return errors.New("couldn't unmarshal bson raw value as Date")
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,18 +16,21 @@ package strfmt
import (
"database/sql/driver"
"errors"
"fmt"
"regexp"
"strconv"
"strings"
"time"
"github.com/globalsign/mgo/bson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
func init() {
d := Duration(0)
// register this format in the default registry
Default.Add("duration", &d, IsDuration)
}
@@ -65,6 +68,9 @@ func IsDuration(str string) bool {
// Duration represents a duration
//
// Duration stores a period of time as a nanosecond count, with the largest
// repesentable duration being approximately 290 years.
//
// swagger:strfmt duration
type Duration time.Duration
@@ -135,7 +141,7 @@ func (d *Duration) Scan(raw interface{}) error {
return nil
}
// Value converts Duration to a primitive value ready to written to a database.
// Value converts Duration to a primitive value ready to be written to a database.
func (d Duration) Value() (driver.Value, error) {
return driver.Value(int64(d)), nil
}
@@ -145,22 +151,26 @@ func (d Duration) String() string {
return time.Duration(d).String()
}
// MarshalJSON returns the Duration as JSON
func (d Duration) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
d.MarshalEasyJSON(&w)
return w.BuildBytes()
}
// MarshalEasyJSON writes the Duration to a easyjson.Writer
func (d Duration) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Duration(d).String())
}
// UnmarshalJSON sets the Duration from JSON
func (d *Duration) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
d.UnmarshalEasyJSON(&l)
return l.Error()
}
// UnmarshalEasyJSON sets the Duration from a easyjson.Lexer
func (d *Duration) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := ParseDuration(data)
@@ -171,3 +181,23 @@ func (d *Duration) UnmarshalEasyJSON(in *jlexer.Lexer) {
*d = Duration(tt)
}
}
// GetBSON returns the Duration a bson.M{} map.
func (d *Duration) GetBSON() (interface{}, error) {
return bson.M{"data": int64(*d)}, nil
}
// SetBSON sets the Duration from raw bson data
func (d *Duration) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(int64); ok {
*d = Duration(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as Duration")
}

View File

@@ -19,24 +19,29 @@ import (
"reflect"
"strings"
"sync"
"time"
"github.com/go-openapi/errors"
"github.com/mitchellh/mapstructure"
)
// Default is the default formats registry
var Default = NewSeededFormats(nil, nil)
// Validator represents a validator for a string format
// Validator represents a validator for a string format.
type Validator func(string) bool
// Format represents a string format
// Format represents a string format.
//
// All implementations of Format provide a string representation and text
// marshaling/unmarshaling interface to be used by encoders (e.g. encoding/json).
type Format interface {
String() string
encoding.TextMarshaler
encoding.TextUnmarshaler
}
// Registry is a registry of string formats
// Registry is a registry of string formats, with a validation method.
type Registry interface {
Add(string, Format, Validator) bool
DelByName(string) bool
@@ -44,6 +49,7 @@ type Registry interface {
ContainsName(string) bool
Validates(string, string) bool
Parse(string, string) (interface{}, error)
MapStructureHookFunc() mapstructure.DecodeHookFunc
}
type knownFormat struct {
@@ -53,7 +59,7 @@ type knownFormat struct {
Validator Validator
}
// NameNormalizer is a function that normalizes a format name
// NameNormalizer is a function that normalizes a format name.
type NameNormalizer func(string) string
// DefaultNameNormalizer removes all dashes
@@ -85,6 +91,77 @@ func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
}
}
// MapStructureHookFunc is a decode hook function for mapstructure
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
return func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) {
if from.Kind() != reflect.String {
return data, nil
}
for _, v := range f.data {
tpe, _ := f.GetType(v.Name)
if to == tpe {
switch v.Name {
case "date":
d, err := time.Parse(RFC3339FullDate, data.(string))
if err != nil {
return nil, err
}
return Date(d), nil
case "datetime":
return ParseDateTime(data.(string))
case "duration":
dur, err := ParseDuration(data.(string))
if err != nil {
return nil, err
}
return Duration(dur), nil
case "uri":
return URI(data.(string)), nil
case "email":
return Email(data.(string)), nil
case "uuid":
return UUID(data.(string)), nil
case "uuid3":
return UUID3(data.(string)), nil
case "uuid4":
return UUID4(data.(string)), nil
case "uuid5":
return UUID5(data.(string)), nil
case "hostname":
return Hostname(data.(string)), nil
case "ipv4":
return IPv4(data.(string)), nil
case "ipv6":
return IPv6(data.(string)), nil
case "mac":
return MAC(data.(string)), nil
case "isbn":
return ISBN(data.(string)), nil
case "isbn10":
return ISBN10(data.(string)), nil
case "isbn13":
return ISBN13(data.(string)), nil
case "creditcard":
return CreditCard(data.(string)), nil
case "ssn":
return SSN(data.(string)), nil
case "hexcolor":
return HexColor(data.(string)), nil
case "rgbcolor":
return RGBColor(data.(string)), nil
case "byte":
return Base64(data.(string)), nil
case "password":
return Password(data.(string)), nil
default:
return nil, errors.InvalidTypeName(v.Name)
}
}
}
return data, nil
}
}
// Add adds a new format, return true if this was a new item instead of a replacement
func (f *defaultFormats) Add(name string, strfmt Format, validator Validator) bool {
f.Lock()
@@ -191,6 +268,10 @@ func (f *defaultFormats) ContainsFormat(strfmt Format) bool {
return false
}
// Validates passed data against format.
//
// Note that the format name is automatically normalized, e.g. one may
// use "date-time" to use the "datetime" format validator.
func (f *defaultFormats) Validates(name, data string) bool {
f.Lock()
defer f.Unlock()
@@ -203,6 +284,9 @@ func (f *defaultFormats) Validates(name, data string) bool {
return false
}
// Parse a string into the appropriate format representation type.
//
// E.g. parsing a string a "date" will return a Date type.
func (f *defaultFormats) Parse(name, data string) (interface{}, error) {
f.Lock()
defer f.Unlock()

13
vendor/github.com/go-openapi/strfmt/go.mod generated vendored Normal file
View File

@@ -0,0 +1,13 @@
module github.com/go-openapi/strfmt
require (
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb
github.com/go-openapi/errors v0.17.0
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329
github.com/mitchellh/mapstructure v1.1.2
github.com/pborman/uuid v1.2.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
)

19
vendor/github.com/go-openapi/strfmt/go.sum generated vendored Normal file
View File

@@ -0,0 +1,19 @@
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvUbuvHW93esHg7F8N/OYeBBcJoTr0=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-openapi/errors v0.17.0 h1:47T+LqPrQUxFXQnB22aLBfsTRFSqWp5y4OiFgQm+/Lw=
github.com/go-openapi/errors v0.17.0/go.mod h1:La0D2x9HoXenv7MDEiAv6vWoe84CXFo0PQRk/jdQlww=
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

View File

@@ -16,11 +16,13 @@ package strfmt
import (
"database/sql/driver"
"errors"
"fmt"
"regexp"
"strings"
"time"
"github.com/globalsign/mgo/bson"
"github.com/mailru/easyjson/jlexer"
"github.com/mailru/easyjson/jwriter"
)
@@ -52,13 +54,17 @@ func IsDateTime(str string) bool {
const (
// RFC3339Millis represents a ISO8601 format to millis instead of to nanos
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
// RFC3339Micro represents a ISO8601 format to micro instead of to nano
RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
// 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{RFC3339Millis, time.RFC3339, time.RFC3339Nano}
dateTimeFormats = []string{RFC3339Micro, RFC3339Millis, time.RFC3339, time.RFC3339Nano}
rxDateTime = regexp.MustCompile(DateTimePattern)
// MarshalFormat sets the time resolution format used for marshaling time (set to milliseconds)
MarshalFormat = RFC3339Millis
)
// ParseDateTime parses a string that represents an ISO8601 time or a unix epoch
@@ -81,7 +87,8 @@ func ParseDateTime(data string) (DateTime, error) {
// DateTime is a time but it serializes to ISO8601 format with millis
// It knows how to read 3 different variations of a RFC3339 date time.
// Most API's we encounter want either millisecond or second precision times. This just tries to make it worry-free.
// Most APIs we encounter want either millisecond or second precision times.
// This just tries to make it worry-free.
//
// swagger:strfmt date-time
type DateTime time.Time
@@ -91,8 +98,9 @@ func NewDateTime() DateTime {
return DateTime(time.Unix(0, 0).UTC())
}
// String converts this time to a string
func (t DateTime) String() string {
return time.Time(t).Format(RFC3339Millis)
return time.Time(t).Format(MarshalFormat)
}
// MarshalText implements the text marshaller interface
@@ -131,25 +139,29 @@ func (t *DateTime) Scan(raw interface{}) error {
// Value converts DateTime to a primitive value ready to written to a database.
func (t DateTime) Value() (driver.Value, error) {
return driver.Value(t), nil
return driver.Value(t.String()), nil
}
// MarshalJSON returns the DateTime as JSON
func (t DateTime) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
t.MarshalEasyJSON(&w)
return w.BuildBytes()
}
// MarshalEasyJSON writes the DateTime to a easyjson.Writer
func (t DateTime) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Time(t).Format(RFC3339Millis))
w.String(time.Time(t).Format(MarshalFormat))
}
// UnmarshalJSON sets the DateTime from JSON
func (t *DateTime) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
t.UnmarshalEasyJSON(&l)
return l.Error()
}
// UnmarshalEasyJSON sets the DateTime from a easyjson.Lexer
func (t *DateTime) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := ParseDateTime(data)
@@ -160,3 +172,24 @@ func (t *DateTime) UnmarshalEasyJSON(in *jlexer.Lexer) {
*t = tt
}
}
// GetBSON returns the DateTime as a bson.M{} map.
func (t *DateTime) GetBSON() (interface{}, error) {
return bson.M{"data": t.String()}, nil
}
// SetBSON sets the DateTime from raw bson data
func (t *DateTime) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
var err error
*t, err = ParseDateTime(data)
return err
}
return errors.New("couldn't unmarshal bson raw value as Duration")
}