diff --git a/go.mod b/go.mod index 45107dcf..71781f31 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403 github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/allegro/bigcache/v3 v3.1.0 - github.com/baidubce/bce-sdk-go v0.9.144 + github.com/baidubce/bce-sdk-go v0.9.146 github.com/basgys/goxml2json v1.1.0 github.com/gin-gonic/gin v1.9.0 github.com/go-playground/locales v0.14.1 github.com/go-playground/universal-translator v0.18.1 - github.com/go-playground/validator/v10 v10.11.2 + github.com/go-playground/validator/v10 v10.12.0 github.com/go-sql-driver/mysql v1.7.0 github.com/lib/pq v1.10.7 github.com/mitchellh/mapstructure v1.5.0 @@ -25,7 +25,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/sirupsen/logrus v1.9.0 github.com/tencentyun/cos-go-sdk-v5 v0.7.41 - go.mongodb.org/mongo-driver v1.11.2 + go.mongodb.org/mongo-driver v1.11.3 go.uber.org/zap v1.24.0 golang.org/x/crypto v0.7.0 golang.org/x/text v0.8.0 @@ -47,7 +47,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect - github.com/goccy/go-json v0.10.1 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect diff --git a/go.sum b/go.sum index c31b0566..59e66bcb 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/baidubce/bce-sdk-go v0.9.144 h1:fKIP6CbDOTKhHySxjEuHHCgTsyQEP2s7Jhsf9l9DH98= -github.com/baidubce/bce-sdk-go v0.9.144/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= +github.com/baidubce/bce-sdk-go v0.9.146 h1:AQlKDhZB53dlJjmTDwQTg1jc7TSPj7v+nnhxvm/JxWs= +github.com/baidubce/bce-sdk-go v0.9.146/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw= github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -115,16 +115,16 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.8.0/go.mod h1:9JhgTzTaE31GZDpH/HSvHiRJrJ3iKAgqqH0Bl/Ocjdk= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= +github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI= +github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/goccy/go-json v0.10.1 h1:lEs5Ob+oOG/Ze199njvzHbhn6p9T+h64F5hRj69iTTo= -github.com/goccy/go-json v0.10.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= @@ -519,8 +519,8 @@ github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxt github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.mongodb.org/mongo-driver v1.11.2 h1:+1v2rDQUWNcGW7/7E0Jvdz51V38XXxJfhzbV17aNHCw= -go.mongodb.org/mongo-driver v1.11.2/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= +go.mongodb.org/mongo-driver v1.11.3 h1:Ql6K6qYHEzB6xvu4+AU0BoRoqf9vFPcc4o7MUIdPW8Y= +go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/vendor/github.com/baidubce/bce-sdk-go/bce/config.go b/vendor/github.com/baidubce/bce-sdk-go/bce/config.go index 0d5ed7f4..91ec0626 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/bce/config.go +++ b/vendor/github.com/baidubce/bce-sdk-go/bce/config.go @@ -26,7 +26,7 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.144" + SDK_VERSION = "0.9.146" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/vendor/github.com/go-playground/validator/v10/README.md b/vendor/github.com/go-playground/validator/v10/README.md index 5f8878d2..84a4b801 100644 --- a/vendor/github.com/go-playground/validator/v10/README.md +++ b/vendor/github.com/go-playground/validator/v10/README.md @@ -1,7 +1,7 @@ Package validator ================= -[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -![Project status](https://img.shields.io/badge/version-10.11.2-green.svg) +[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +![Project status](https://img.shields.io/badge/version-10.12.0-green.svg) [![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator) [![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator) @@ -73,8 +73,8 @@ Baked-in Validations | - | - | | eqcsfield | Field Equals Another Field (relative)| | eqfield | Field Equals Another Field | -| fieldcontains | NOT DOCUMENTED IN doc.go | -| fieldexcludes | NOT DOCUMENTED IN doc.go | +| fieldcontains | Check the indicated characters are present in the Field | +| fieldexcludes | Check the indicated characters are not present in the field | | gtcsfield | Field Greater Than Another Relative Field | | gtecsfield | Field Greater Than or Equal To Another Relative Field | | gtefield | Field Greater Than or Equal To Another Field | @@ -114,6 +114,7 @@ Baked-in Validations | unix_addr | Unix domain socket end point Address | | uri | URI String | | url | URL String | +| http_url | HTTP URL String | | url_encoded | URL Encoded | | urn_rfc2141 | Urn RFC 2141 String | @@ -137,7 +138,7 @@ Baked-in Validations | excludesrune | Excludes Rune | | lowercase | Lowercase | | multibyte | Multi-Byte Characters | -| number | NOT DOCUMENTED IN doc.go | +| number | Number | | numeric | Numeric | | printascii | Printable ASCII | | startsnotwith | Starts Not With | @@ -149,11 +150,14 @@ Baked-in Validations | - | - | | base64 | Base64 String | | base64url | Base64URL String | +| base64rawurl | Base64RawURL String | | bic | Business Identifier Code (ISO 9362) | | bcp47_language_tag | Language tag (BCP 47) | | btc_addr | Bitcoin Address | | btc_addr_bech32 | Bitcoin Bech32 Address (segwit) | | credit_card | Credit Card Number | +| mongodb | MongoDB ObjectID | +| cron | Cron | | datetime | Datetime | | e164 | e164 formatted phone number | | email | E-mail String @@ -176,6 +180,7 @@ Baked-in Validations | jwt | JSON Web Token (JWT) | | latitude | Latitude | | longitude | Longitude | +| luhn_checksum | Luhn Algorithm Checksum (for strings and (u)int) | | postcode_iso3166_alpha2 | Postcode | | postcode_iso3166_alpha2_field | Postcode | | rgb | RGB String | @@ -202,22 +207,27 @@ Baked-in Validations | tiger192 | TIGER192 hash | | semver | Semantic Versioning 2.0.0 | | ulid | Universally Unique Lexicographically Sortable Identifier ULID | +| cve | Common Vulnerabilities and Exposures Identifier (CVE id) | ### Comparisons: | Tag | Description | | - | - | | eq | Equals | +| eq_ignore_case | Equals ignoring case | | gt | Greater than| | gte | Greater than or equal | | lt | Less Than | | lte | Less Than or Equal | | ne | Not Equal | +| ne_ignore_case | Not Equal ignoring case | ### Other: | Tag | Description | | - | - | -| dir | Directory | -| file | File path | +| dir | Existing Directory | +| dirpath | Directory Path | +| file | Existing File | +| filepath | File Path | | isdefault | Is Default | | len | Length | | max | Maximum | diff --git a/vendor/github.com/go-playground/validator/v10/baked_in.go b/vendor/github.com/go-playground/validator/v10/baked_in.go index c9b1db40..48a01ca3 100644 --- a/vendor/github.com/go-playground/validator/v10/baked_in.go +++ b/vendor/github.com/go-playground/validator/v10/baked_in.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io/fs" "net" "net/url" "os" @@ -14,13 +15,14 @@ import ( "strconv" "strings" "sync" + "syscall" "time" "unicode/utf8" "golang.org/x/crypto/sha3" "golang.org/x/text/language" - urn "github.com/leodido/go-urn" + "github.com/leodido/go-urn" ) // Func accepts a FieldLevel interface for all validation needs. The return @@ -86,7 +88,9 @@ var ( "min": hasMinOf, "max": hasMaxOf, "eq": isEq, + "eq_ignore_case": isEqIgnoreCase, "ne": isNe, + "ne_ignore_case": isNeIgnoreCase, "lt": isLt, "lte": isLte, "gt": isGt, @@ -121,11 +125,14 @@ var ( "e164": isE164, "email": isEmail, "url": isURL, + "http_url": isHttpURL, "uri": isURI, "urn_rfc2141": isUrnRFC2141, // RFC 2141 "file": isFile, + "filepath": isFilePath, "base64": isBase64, "base64url": isBase64URL, + "base64rawurl": isBase64RawURL, "contains": contains, "containsany": containsAny, "containsrune": containsRune, @@ -140,6 +147,7 @@ var ( "isbn10": isISBN10, "isbn13": isISBN13, "eth_addr": isEthereumAddress, + "eth_addr_checksum": isEthereumAddressChecksum, "btc_addr": isBitcoinAddress, "btc_addr_bech32": isBitcoinBech32Address, "uuid": isUUID, @@ -194,6 +202,7 @@ var ( "html_encoded": isHTMLEncoded, "url_encoded": isURLEncoded, "dir": isDir, + "dirpath": isDirPath, "json": isJSON, "jwt": isJWT, "hostname_port": isHostnamePort, @@ -214,6 +223,10 @@ var ( "semver": isSemverFormat, "dns_rfc1035_label": isDnsRFC1035LabelFormat, "credit_card": isCreditCard, + "cve": isCveFormat, + "luhn_checksum": hasLuhnChecksum, + "mongodb": isMongoDB, + "cron": isCron, } ) @@ -307,18 +320,42 @@ func isUnique(fl FieldLevel) bool { } m := reflect.MakeMap(reflect.MapOf(sfTyp, v.Type())) + var fieldlen int for i := 0; i < field.Len(); i++ { - m.SetMapIndex(reflect.Indirect(reflect.Indirect(field.Index(i)).FieldByName(param)), v) + key := reflect.Indirect(reflect.Indirect(field.Index(i)).FieldByName(param)) + if key.IsValid() { + fieldlen++ + m.SetMapIndex(key, v) + } } - return field.Len() == m.Len() + return fieldlen == m.Len() case reflect.Map: - m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type())) + var m reflect.Value + if field.Type().Elem().Kind() == reflect.Ptr { + m = reflect.MakeMap(reflect.MapOf(field.Type().Elem().Elem(), v.Type())) + } else { + m = reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type())) + } for _, k := range field.MapKeys() { - m.SetMapIndex(field.MapIndex(k), v) + m.SetMapIndex(reflect.Indirect(field.MapIndex(k)), v) } + return field.Len() == m.Len() default: + if parent := fl.Parent(); parent.Kind() == reflect.Struct { + uniqueField := parent.FieldByName(param) + if uniqueField == reflect.ValueOf(nil) { + panic(fmt.Sprintf("Bad field name provided %s", param)) + } + + if uniqueField.Kind() != field.Kind() { + panic(fmt.Sprintf("Bad field type %T:%T", field.Interface(), uniqueField.Interface())) + } + + return field.Interface() != uniqueField.Interface() + } + panic(fmt.Sprintf("Bad field type %T", field.Interface())) } } @@ -613,14 +650,16 @@ func isISBN10(fl FieldLevel) bool { func isEthereumAddress(fl FieldLevel) bool { address := fl.Field().String() + return ethAddressRegex.MatchString(address) +} + +// isEthereumAddressChecksum is the validation function for validating if the field's value is a valid checksumed Ethereum address. +func isEthereumAddressChecksum(fl FieldLevel) bool { + address := fl.Field().String() + if !ethAddressRegex.MatchString(address) { return false } - - if ethAddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) { - return true - } - // Checksum validation. Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md address = address[2:] // Skip "0x" prefix. h := sha3.NewLegacyKeccak256() @@ -889,6 +928,12 @@ func isNe(fl FieldLevel) bool { return !isEq(fl) } +// isNe is the validation function for validating that the field's string value does not equal the +// provided param value. The comparison is case-insensitive +func isNeIgnoreCase(fl FieldLevel) bool { + return !isEqIgnoreCase(fl) +} + // isLteCrossStructField is the validation function for validating if the current field's value is less than or equal to the field, within a separate struct, specified by the param's value. func isLteCrossStructField(fl FieldLevel) bool { field := fl.Field() @@ -1260,6 +1305,22 @@ func isEq(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } +// isEqIgnoreCase is the validation function for validating if the current field's string value is +// equal to the param's value. +// The comparison is case-insensitive. +func isEqIgnoreCase(fl FieldLevel) bool { + field := fl.Field() + param := fl.Param() + + switch field.Kind() { + + case reflect.String: + return strings.EqualFold(field.String(), param) + } + + panic(fmt.Sprintf("Bad field type %T", field.Interface())) +} + // isPostcodeByIso3166Alpha2 validates by value which is country code in iso 3166 alpha 2 // example: `postcode_iso3166_alpha2=US` func isPostcodeByIso3166Alpha2(fl FieldLevel) bool { @@ -1311,6 +1372,11 @@ func isBase64URL(fl FieldLevel) bool { return base64URLRegex.MatchString(fl.Field().String()) } +// isBase64RawURL is the validation function for validating if the current field's value is a valid base64 URL safe string without '=' padding. +func isBase64RawURL(fl FieldLevel) bool { + return base64RawURLRegex.MatchString(fl.Field().String()) +} + // isURI is the validation function for validating if the current field's value is a valid URI. func isURI(fl FieldLevel) bool { field := fl.Field() @@ -1370,6 +1436,23 @@ func isURL(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } +// isHttpURL is the validation function for validating if the current field's value is a valid HTTP(s) URL. +func isHttpURL(fl FieldLevel) bool { + if !isURL(fl) { + return false + } + + field := fl.Field() + switch field.Kind() { + case reflect.String: + + s := strings.ToLower(field.String()) + return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") + } + + panic(fmt.Sprintf("Bad field type %T", field.Interface())) +} + // isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141. func isUrnRFC2141(fl FieldLevel) bool { field := fl.Field() @@ -1387,7 +1470,7 @@ func isUrnRFC2141(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } -// isFile is the validation function for validating if the current field's value is a valid file path. +// isFile is the validation function for validating if the current field's value is a valid existing file path. func isFile(fl FieldLevel) bool { field := fl.Field() @@ -1404,6 +1487,57 @@ func isFile(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } +// isFilePath is the validation function for validating if the current field's value is a valid file path. +func isFilePath(fl FieldLevel) bool { + + var exists bool + var err error + + field := fl.Field() + + // If it exists, it obviously is valid. + // This is done first to avoid code duplication and unnecessary additional logic. + if exists = isFile(fl); exists { + return true + } + + // It does not exist but may still be a valid filepath. + switch field.Kind() { + case reflect.String: + // Every OS allows for whitespace, but none + // let you use a file with no filename (to my knowledge). + // Unless you're dealing with raw inodes, but I digress. + if strings.TrimSpace(field.String()) == "" { + return false + } + // We make sure it isn't a directory. + if strings.HasSuffix(field.String(), string(os.PathSeparator)) { + return false + } + if _, err = os.Stat(field.String()); err != nil { + switch t := err.(type) { + case *fs.PathError: + if t.Err == syscall.EINVAL { + // It's definitely an invalid character in the filepath. + return false + } + // It could be a permission error, a does-not-exist error, etc. + // Out-of-scope for this validation, though. + return true + default: + // Something went *seriously* wrong. + /* + Per https://pkg.go.dev/os#Stat: + "If there is an error, it will be of type *PathError." + */ + panic(err) + } + } + } + + panic(fmt.Sprintf("Bad field type %T", field.Interface())) +} + // isE164 is the validation function for validating if the current field's value is a valid e.164 formatted phone number. func isE164(fl FieldLevel) bool { return e164Regex.MatchString(fl.Field().String()) @@ -1539,7 +1673,9 @@ func requireCheckFieldKind(fl FieldLevel, param string, defaultNotFoundValue boo } // requireCheckFieldValue is a func for check field value -func requireCheckFieldValue(fl FieldLevel, param string, value string, defaultNotFoundValue bool) bool { +func requireCheckFieldValue( + fl FieldLevel, param string, value string, defaultNotFoundValue bool, +) bool { field, kind, _, found := fl.GetStructFieldOKAdvanced2(fl.Parent(), param) if !found { return defaultNotFoundValue @@ -1623,10 +1759,10 @@ func excludedUnless(fl FieldLevel) bool { } for i := 0; i < len(params); i += 2 { if !requireCheckFieldValue(fl, params[i], params[i+1], false) { - return true + return !hasValue(fl) } } - return !hasValue(fl) + return true } // excludedWith is the validation function @@ -2275,7 +2411,7 @@ func isFQDN(fl FieldLevel) bool { return fqdnRegexRFC1123.MatchString(val) } -// isDir is the validation function for validating if the current field's value is a valid directory. +// isDir is the validation function for validating if the current field's value is a valid existing directory. func isDir(fl FieldLevel) bool { field := fl.Field() @@ -2291,6 +2427,64 @@ func isDir(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } +// isDirPath is the validation function for validating if the current field's value is a valid directory. +func isDirPath(fl FieldLevel) bool { + + var exists bool + var err error + + field := fl.Field() + + // If it exists, it obviously is valid. + // This is done first to avoid code duplication and unnecessary additional logic. + if exists = isDir(fl); exists { + return true + } + + // It does not exist but may still be a valid path. + switch field.Kind() { + case reflect.String: + // Every OS allows for whitespace, but none + // let you use a dir with no name (to my knowledge). + // Unless you're dealing with raw inodes, but I digress. + if strings.TrimSpace(field.String()) == "" { + return false + } + if _, err = os.Stat(field.String()); err != nil { + switch t := err.(type) { + case *fs.PathError: + if t.Err == syscall.EINVAL { + // It's definitely an invalid character in the path. + return false + } + // It could be a permission error, a does-not-exist error, etc. + // Out-of-scope for this validation, though. + // Lastly, we make sure it is a directory. + if strings.HasSuffix(field.String(), string(os.PathSeparator)) { + return true + } else { + return false + } + default: + // Something went *seriously* wrong. + /* + Per https://pkg.go.dev/os#Stat: + "If there is an error, it will be of type *PathError." + */ + panic(err) + } + } + // We repeat the check here to make sure it is an explicit directory in case the above os.Stat didn't trigger an error. + if strings.HasSuffix(field.String(), string(os.PathSeparator)) { + return true + } else { + return false + } + } + + panic(fmt.Sprintf("Bad field type %T", field.Interface())) +} + // isJSON is the validation function for validating if the current field's value is a valid json string. func isJSON(fl FieldLevel) bool { field := fl.Field() @@ -2316,7 +2510,9 @@ func isHostnamePort(fl FieldLevel) bool { return false } // Port must be a iny <= 65535. - if portNum, err := strconv.ParseInt(port, 10, 32); err != nil || portNum > 65535 || portNum < 1 { + if portNum, err := strconv.ParseInt( + port, 10, 32, + ); err != nil || portNum > 65535 || portNum < 1 { return false } @@ -2479,6 +2675,13 @@ func isSemverFormat(fl FieldLevel) bool { return semverRegex.MatchString(semverString) } +// isCveFormat is the validation function for validating if the current field's value is a valid cve id, defined in CVE mitre org +func isCveFormat(fl FieldLevel) bool { + cveString := fl.Field().String() + + return cveRegex.MatchString(cveString) +} + // isDnsRFC1035LabelFormat is the validation function // for validating if the current field's value is // a valid dns RFC 1035 label, defined in RFC 1035. @@ -2487,6 +2690,35 @@ func isDnsRFC1035LabelFormat(fl FieldLevel) bool { return dnsRegexRFC1035Label.MatchString(val) } +// digitsHaveLuhnChecksum returns true if and only if the last element of the given digits slice is the Luhn checksum of the previous elements +func digitsHaveLuhnChecksum(digits []string) bool { + size := len(digits) + sum := 0 + for i, digit := range digits { + value, err := strconv.Atoi(digit) + if err != nil { + return false + } + if size%2 == 0 && i%2 == 0 || size%2 == 1 && i%2 == 1 { + v := value * 2 + if v >= 10 { + sum += 1 + (v % 10) + } else { + sum += v + } + } else { + sum += value + } + } + return (sum % 10) == 0 +} + +// isMongoDB is the validation function for validating if the current field's value is valid mongoDB objectID +func isMongoDB(fl FieldLevel) bool { + val := fl.Field().String() + return mongodbRegex.MatchString(val) +} + // isCreditCard is the validation function for validating if the current field's value is a valid credit card number func isCreditCard(fl FieldLevel) bool { val := fl.Field().String() @@ -2505,22 +2737,33 @@ func isCreditCard(fl FieldLevel) bool { return false } - sum := 0 - for i, digit := range ccDigits { - value, err := strconv.Atoi(digit) - if err != nil { - return false - } - if size%2 == 0 && i%2 == 0 || size%2 == 1 && i%2 == 1 { - v := value * 2 - if v >= 10 { - sum += 1 + (v % 10) - } else { - sum += v - } - } else { - sum += value - } + return digitsHaveLuhnChecksum(ccDigits) +} + +// hasLuhnChecksum is the validation for validating if the current field's value has a valid Luhn checksum +func hasLuhnChecksum(fl FieldLevel) bool { + field := fl.Field() + var str string // convert to a string which will then be split into single digits; easier and more readable than shifting/extracting single digits from a number + switch field.Kind() { + case reflect.String: + str = field.String() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + str = strconv.FormatInt(field.Int(), 10) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + str = strconv.FormatUint(field.Uint(), 10) + default: + panic(fmt.Sprintf("Bad field type %T", field.Interface())) } - return (sum % 10) == 0 + size := len(str) + if size < 2 { // there has to be at least one digit that carries a meaning + the checksum + return false + } + digits := strings.Split(str, "") + return digitsHaveLuhnChecksum(digits) +} + +// isCron is the validation function for validating if the current field's value is a valid cron expression +func isCron(fl FieldLevel) bool { + cronString := fl.Field().String() + return cronRegex.MatchString(cronString) } diff --git a/vendor/github.com/go-playground/validator/v10/cache.go b/vendor/github.com/go-playground/validator/v10/cache.go index 7b84c91f..bbfd2a4a 100644 --- a/vendor/github.com/go-playground/validator/v10/cache.go +++ b/vendor/github.com/go-playground/validator/v10/cache.go @@ -120,7 +120,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr var fld reflect.StructField var tag string var customName string - + for i := 0; i < numFields; i++ { fld = typ.Field(i) diff --git a/vendor/github.com/go-playground/validator/v10/country_codes.go b/vendor/github.com/go-playground/validator/v10/country_codes.go index 0d9eda03..b6c7a90c 100644 --- a/vendor/github.com/go-playground/validator/v10/country_codes.go +++ b/vendor/github.com/go-playground/validator/v10/country_codes.go @@ -51,7 +51,7 @@ var iso3166_1_alpha2 = map[string]bool{ "TV": true, "UG": true, "UA": true, "AE": true, "GB": true, "US": true, "UM": true, "UY": true, "UZ": true, "VU": true, "VE": true, "VN": true, "VG": true, "VI": true, "WF": true, - "EH": true, "YE": true, "ZM": true, "ZW": true, + "EH": true, "YE": true, "ZM": true, "ZW": true, "XK": true, } var iso3166_1_alpha3 = map[string]bool{ @@ -105,7 +105,7 @@ var iso3166_1_alpha3 = map[string]bool{ "UGA": true, "UKR": true, "ARE": true, "GBR": true, "UMI": true, "USA": true, "URY": true, "UZB": true, "VUT": true, "VEN": true, "VNM": true, "VGB": true, "VIR": true, "WLF": true, "ESH": true, - "YEM": true, "ZMB": true, "ZWE": true, "ALA": true, + "YEM": true, "ZMB": true, "ZWE": true, "ALA": true, "UNK": true, } var iso3166_1_alpha_numeric = map[int]bool{ // see: https://www.iso.org/iso-3166-country-codes.html @@ -158,7 +158,7 @@ var iso3166_1_alpha_numeric = map[int]bool{ 800: true, 804: true, 784: true, 826: true, 581: true, 840: true, 858: true, 860: true, 548: true, 862: true, 704: true, 92: true, 850: true, 876: true, 732: true, - 887: true, 894: true, 716: true, 248: true, + 887: true, 894: true, 716: true, 248: true, 153:true, } var iso3166_2 = map[string]bool{ diff --git a/vendor/github.com/go-playground/validator/v10/doc.go b/vendor/github.com/go-playground/validator/v10/doc.go index 7341c67d..41784620 100644 --- a/vendor/github.com/go-playground/validator/v10/doc.go +++ b/vendor/github.com/go-playground/validator/v10/doc.go @@ -7,7 +7,7 @@ and has the ability to dive into arrays and maps of any type. see more examples https://github.com/go-playground/validator/tree/master/_examples -Singleton +# Singleton Validator is designed to be thread-safe and used as a singleton instance. It caches information about your struct and validations, @@ -15,7 +15,7 @@ in essence only parsing your validation tags once per struct type. Using multiple instances neglects the benefit of caching. The not thread-safe functions are explicitly marked as such in the documentation. -Validation Functions Return Type error +# Validation Functions Return Type error Doing things this way is actually the way the standard library does, see the file.Open method here: @@ -34,7 +34,7 @@ if the error returned is not nil, and if it's not check if error is InvalidValidationError ( if necessary, most of the time it isn't ) type cast it to type ValidationErrors like so err.(validator.ValidationErrors). -Custom Validation Functions +# Custom Validation Functions Custom Validation functions can be added. Example: @@ -52,21 +52,21 @@ Custom Validation functions can be added. Example: // NOTES: using the same tag name as an existing function // will overwrite the existing one -Cross-Field Validation +# Cross-Field Validation Cross-Field Validation can be done via the following tags: - - eqfield - - nefield - - gtfield - - gtefield - - ltfield - - ltefield - - eqcsfield - - necsfield - - gtcsfield - - gtecsfield - - ltcsfield - - ltecsfield + - eqfield + - nefield + - gtfield + - gtefield + - ltfield + - ltefield + - eqcsfield + - necsfield + - gtcsfield + - gtecsfield + - ltcsfield + - ltecsfield If, however, some custom cross-field validation is required, it can be done using a custom validation. @@ -106,7 +106,7 @@ used "eqcsfield" it could be multiple levels down. Example: // whatever you pass, struct, field... // when calling validate.Field(field, tag) val will be nil -Multiple Validators +# Multiple Validators Multiple validators on a field will process in the order defined. Example: @@ -124,7 +124,7 @@ Bad Validator definitions are not handled by the library. Example: // this definition of min max will never succeed -Using Validator Tags +# Using Validator Tags Baked In Cross-Field validation only compares fields on the same struct. If Cross-Field + Cross-Struct validation is needed you should implement your @@ -150,20 +150,18 @@ so the above will become excludesall=0x7C Field `validate:"excludesall=0x7C"` // GOOD! Use the UTF-8 hex representation. } - -Baked In Validators and Tags +# Baked In Validators and Tags Here is a list of the current built in validators: - -Skip Field +# Skip Field Tells the validation to skip this struct field; this is particularly handy in ignoring embedded structs from being validated. (Usage: -) - Usage: - + Usage: - -Or Operator +# Or Operator This is the 'or' operator allowing multiple validators to be used and accepted. (Usage: rgb|rgba) <-- this would allow either rgb or rgba @@ -172,7 +170,7 @@ colors to be accepted. This can also be combined with 'and' for example Usage: | -StructOnly +# StructOnly When a field that is a nested struct is encountered, and contains this flag any validation on the nested struct will be run, but none of the nested @@ -182,13 +180,13 @@ NOTE: only "required" and "omitempty" can be used on a struct itself. Usage: structonly -NoStructLevel +# NoStructLevel Same as structonly tag except that any struct level validations will not run. Usage: nostructlevel -Omit Empty +# Omit Empty Allows conditional validation, for example if a field is not set with a value (Determined by the "required" validator) then other validation @@ -196,7 +194,7 @@ such as min or max won't run, but if a value is set validation will run. Usage: omitempty -Dive +# Dive This tells the validator to dive into a slice, array or map and validate that level of the slice, array or map with the validation tags that follow. @@ -232,19 +230,19 @@ require another 'keys' and 'endkeys' tag. These tags are only valid for maps. Example #1 - map[string]string with validation tag "gt=0,dive,keys,eg=1|eq=2,endkeys,required" + map[string]string with validation tag "gt=0,dive,keys,eq=1|eq=2,endkeys,required" // gt=0 will be applied to the map itself - // eg=1|eq=2 will be applied to the map keys + // eq=1|eq=2 will be applied to the map keys // required will be applied to map values Example #2 map[[2]string]string with validation tag "gt=0,dive,keys,dive,eq=1|eq=2,endkeys,required" // gt=0 will be applied to the map itself - // eg=1|eq=2 will be applied to each array element in the the map keys + // eq=1|eq=2 will be applied to each array element in the the map keys // required will be applied to map values -Required +# Required This validates that the value is not the data types default zero value. For numbers ensures value is not zero. For strings ensures value is @@ -253,7 +251,7 @@ ensures the value is not nil. Usage: required -Required If +# Required If The field under validation must be present and not empty only if all the other specified fields are equal to the value following the specified @@ -270,7 +268,7 @@ Examples: // require the field if the Field1 and Field2 is equal to the value respectively: Usage: required_if=Field1 foo Field2 bar -Required Unless +# Required Unless The field under validation must be present and not empty unless all the other specified fields are equal to the value following the specified @@ -287,7 +285,7 @@ Examples: // require the field unless the Field1 and Field2 is equal to the value respectively: Usage: required_unless=Field1 foo Field2 bar -Required With +# Required With The field under validation must be present and not empty only if any of the other specified fields are present. For strings ensures value is @@ -304,7 +302,7 @@ Examples: // require the field if the Field1 or Field2 is present: Usage: required_with=Field1 Field2 -Required With All +# Required With All The field under validation must be present and not empty only if all of the other specified fields are present. For strings ensures value is @@ -318,7 +316,7 @@ Example: // require the field if the Field1 and Field2 is present: Usage: required_with_all=Field1 Field2 -Required Without +# Required Without The field under validation must be present and not empty only when any of the other specified fields are not present. For strings ensures value is @@ -335,7 +333,7 @@ Examples: // require the field if the Field1 or Field2 is not present: Usage: required_without=Field1 Field2 -Required Without All +# Required Without All The field under validation must be present and not empty only when all of the other specified fields are not present. For strings ensures value is @@ -349,7 +347,7 @@ Example: // require the field if the Field1 and Field2 is not present: Usage: required_without_all=Field1 Field2 -Excluded If +# Excluded If The field under validation must not be present or not empty only if all the other specified fields are equal to the value following the specified @@ -366,7 +364,7 @@ Examples: // exclude the field if the Field1 and Field2 is equal to the value respectively: Usage: excluded_if=Field1 foo Field2 bar -Excluded Unless +# Excluded Unless The field under validation must not be present or empty unless all the other specified fields are equal to the value following the specified @@ -383,14 +381,14 @@ Examples: // exclude the field unless the Field1 and Field2 is equal to the value respectively: Usage: excluded_unless=Field1 foo Field2 bar -Is Default +# Is Default This validates that the value is the default value and is almost the opposite of required. Usage: isdefault -Length +# Length For numbers, length will ensure that the value is equal to the parameter given. For strings, it checks that @@ -408,7 +406,7 @@ in the parameter. Usage: len=1h30m -Maximum +# Maximum For numbers, max will ensure that the value is less than or equal to the parameter given. For strings, it checks @@ -426,7 +424,7 @@ duration given in the parameter. Usage: max=1h30m -Minimum +# Minimum For numbers, min will ensure that the value is greater or equal to the parameter given. For strings, it checks that @@ -444,7 +442,7 @@ the duration given in the parameter. Usage: min=1h30m -Equals +# Equals For strings & numbers, eq will ensure that the value is equal to the parameter given. For slices, arrays, and maps, @@ -461,7 +459,7 @@ in the parameter. Usage: eq=1h30m -Not Equal +# Not Equal For strings & numbers, ne will ensure that the value is not equal to the parameter given. For slices, arrays, and maps, @@ -478,7 +476,7 @@ given in the parameter. Usage: ne=1h30m -One Of +# One Of For strings, ints, and uints, oneof will ensure that the value is one of the values in the parameter. The parameter should be @@ -486,11 +484,11 @@ a list of values separated by whitespace. Values may be strings or numbers. To match strings with spaces in them, include the target string between single quotes. - Usage: oneof=red green - oneof='red green' 'blue yellow' - oneof=5 7 9 + Usage: oneof=red green + oneof='red green' 'blue yellow' + oneof=5 7 9 -Greater Than +# Greater Than For numbers, this will ensure that the value is greater than the parameter given. For strings, it checks that the string length @@ -514,7 +512,7 @@ given in the parameter. Usage: gt=1h30m -Greater Than or Equal +# Greater Than or Equal Same as 'min' above. Kept both to make terminology with 'len' easier. @@ -535,7 +533,7 @@ the duration given in the parameter. Usage: gte=1h30m -Less Than +# Less Than For numbers, this will ensure that the value is less than the parameter given. For strings, it checks that the string length is less than that number of @@ -558,7 +556,7 @@ in the parameter. Usage: lt=1h30m -Less Than or Equal +# Less Than or Equal Same as 'max' above. Kept both to make terminology with 'len' easier. @@ -579,7 +577,7 @@ duration given in the parameter. Usage: lte=1h30m -Field Equals Another Field +# Field Equals Another Field This will validate the field value against another fields value either within a struct or passed in field. @@ -601,7 +599,7 @@ to the top level struct. Usage: eqcsfield=InnerStructField.Field) -Field Does Not Equal Another Field +# Field Does Not Equal Another Field This will validate the field value against another fields value either within a struct or passed in field. @@ -623,7 +621,7 @@ relative to the top level struct. Usage: necsfield=InnerStructField.Field -Field Greater Than Another Field +# Field Greater Than Another Field Only valid for Numbers, time.Duration and time.Time types, this will validate the field value against another fields value either within a struct or passed in @@ -639,14 +637,14 @@ Example #2: // Validating by field: validate.VarWithValue(start, end, "gtfield") -Field Greater Than Another Relative Field +# Field Greater Than Another Relative Field This does the same as gtfield except that it validates the field provided relative to the top level struct. Usage: gtcsfield=InnerStructField.Field -Field Greater Than or Equal To Another Field +# Field Greater Than or Equal To Another Field Only valid for Numbers, time.Duration and time.Time types, this will validate the field value against another fields value either within a struct or passed in @@ -662,14 +660,14 @@ Example #2: // Validating by field: validate.VarWithValue(start, end, "gtefield") -Field Greater Than or Equal To Another Relative Field +# Field Greater Than or Equal To Another Relative Field This does the same as gtefield except that it validates the field provided relative to the top level struct. Usage: gtecsfield=InnerStructField.Field -Less Than Another Field +# Less Than Another Field Only valid for Numbers, time.Duration and time.Time types, this will validate the field value against another fields value either within a struct or passed in @@ -685,14 +683,14 @@ Example #2: // Validating by field: validate.VarWithValue(start, end, "ltfield") -Less Than Another Relative Field +# Less Than Another Relative Field This does the same as ltfield except that it validates the field provided relative to the top level struct. Usage: ltcsfield=InnerStructField.Field -Less Than or Equal To Another Field +# Less Than or Equal To Another Field Only valid for Numbers, time.Duration and time.Time types, this will validate the field value against another fields value either within a struct or passed in @@ -708,14 +706,14 @@ Example #2: // Validating by field: validate.VarWithValue(start, end, "ltefield") -Less Than or Equal To Another Relative Field +# Less Than or Equal To Another Relative Field This does the same as ltefield except that it validates the field provided relative to the top level struct. Usage: ltecsfield=InnerStructField.Field -Field Contains Another Field +# Field Contains Another Field This does the same as contains except for struct fields. It should only be used with string types. See the behavior of reflect.Value.String() for behavior on @@ -723,7 +721,7 @@ other types. Usage: containsfield=InnerStructField.Field -Field Excludes Another Field +# Field Excludes Another Field This does the same as excludes except for struct fields. It should only be used with string types. See the behavior of reflect.Value.String() for behavior on @@ -731,7 +729,7 @@ other types. Usage: excludesfield=InnerStructField.Field -Unique +# Unique For arrays & slices, unique will ensure that there are no duplicates. For maps, unique will ensure that there are no duplicate values. @@ -744,44 +742,44 @@ in a field of the struct specified via a parameter. // For slices of struct: Usage: unique=field -Alpha Only +# Alpha Only This validates that a string value contains ASCII alpha characters only Usage: alpha -Alphanumeric +# Alphanumeric This validates that a string value contains ASCII alphanumeric characters only Usage: alphanum -Alpha Unicode +# Alpha Unicode This validates that a string value contains unicode alpha characters only Usage: alphaunicode -Alphanumeric Unicode +# Alphanumeric Unicode This validates that a string value contains unicode alphanumeric characters only Usage: alphanumunicode -Boolean +# Boolean This validates that a string value can successfully be parsed into a boolean with strconv.ParseBool Usage: boolean -Number +# Number This validates that a string value contains number values only. For integers or float it returns true. Usage: number -Numeric +# Numeric This validates that a string value contains a basic numeric value. basic excludes exponents etc... @@ -789,63 +787,63 @@ for integers or float it returns true. Usage: numeric -Hexadecimal String +# Hexadecimal String This validates that a string value contains a valid hexadecimal. Usage: hexadecimal -Hexcolor String +# Hexcolor String This validates that a string value contains a valid hex color including hashtag (#) - Usage: hexcolor + Usage: hexcolor -Lowercase String +# Lowercase String This validates that a string value contains only lowercase characters. An empty string is not a valid lowercase string. Usage: lowercase -Uppercase String +# Uppercase String This validates that a string value contains only uppercase characters. An empty string is not a valid uppercase string. Usage: uppercase -RGB String +# RGB String This validates that a string value contains a valid rgb color Usage: rgb -RGBA String +# RGBA String This validates that a string value contains a valid rgba color Usage: rgba -HSL String +# HSL String This validates that a string value contains a valid hsl color Usage: hsl -HSLA String +# HSLA String This validates that a string value contains a valid hsla color Usage: hsla -E.164 Phone Number String +# E.164 Phone Number String This validates that a string value contains a valid E.164 Phone number https://en.wikipedia.org/wiki/E.164 (ex. +1123456789) Usage: e164 -E-mail String +# E-mail String This validates that a string value contains a valid email This may not conform to all possibilities of any rfc standard, but neither @@ -853,19 +851,20 @@ does any email provider accept all possibilities. Usage: email -JSON String +# JSON String This validates that a string value is valid JSON Usage: json -JWT String +# JWT String This validates that a string value is a valid JWT Usage: jwt -File path + +# File This validates that a string value contains a valid file path and that the file exists on the machine. @@ -873,7 +872,17 @@ This is done using os.Stat, which is a platform independent function. Usage: file -URL String + +# File Path + +This validates that a string value contains a valid file path but does not +validate the existence of that file. +This is done using os.Stat, which is a platform independent function. + + Usage: filepath + + +# URL String This validates that a string value contains a valid url This will accept any url the golang request uri accepts but must contain @@ -881,21 +890,21 @@ a schema for example http:// or rtmp:// Usage: url -URI String +# URI String This validates that a string value contains a valid uri This will accept any uri the golang request uri accepts Usage: uri -Urn RFC 2141 String +# Urn RFC 2141 String This validataes that a string value contains a valid URN according to the RFC 2141 spec. Usage: urn_rfc2141 -Base64 String +# Base64 String This validates that a string value contains a valid base64 value. Although an empty string is valid base64 this will report an empty string @@ -904,7 +913,7 @@ this with the omitempty tag. Usage: base64 -Base64URL String +# Base64URL String This validates that a string value contains a valid base64 URL safe value according the the RFC4648 spec. @@ -914,7 +923,19 @@ you can use this with the omitempty tag. Usage: base64url -Bitcoin Address + +# Base64RawURL String + +This validates that a string value contains a valid base64 URL safe value, +but without = padding, according the the RFC4648 spec, section 3.2. +Although an empty string is a valid base64 URL safe value, this will report +an empty string as an error, if you wish to accept an empty string as valid +you can use this with the omitempty tag. + + Usage: base64url + + +# Bitcoin Address This validates that a string value contains a valid bitcoin address. The format of the string is checked to ensure it matches one of the three formats @@ -930,266 +951,266 @@ Special thanks to Pieter Wuille for providng reference implementations. Usage: btc_addr_bech32 -Ethereum Address +# Ethereum Address This validates that a string value contains a valid ethereum address. The format of the string is checked to ensure it matches the standard Ethereum address format. Usage: eth_addr -Contains +# Contains This validates that a string value contains the substring value. Usage: contains=@ -Contains Any +# Contains Any This validates that a string value contains any Unicode code points in the substring value. Usage: containsany=!@#? -Contains Rune +# Contains Rune This validates that a string value contains the supplied rune value. Usage: containsrune=@ -Excludes +# Excludes This validates that a string value does not contain the substring value. Usage: excludes=@ -Excludes All +# Excludes All This validates that a string value does not contain any Unicode code points in the substring value. Usage: excludesall=!@#? -Excludes Rune +# Excludes Rune This validates that a string value does not contain the supplied rune value. Usage: excludesrune=@ -Starts With +# Starts With This validates that a string value starts with the supplied string value Usage: startswith=hello -Ends With +# Ends With This validates that a string value ends with the supplied string value Usage: endswith=goodbye -Does Not Start With +# Does Not Start With This validates that a string value does not start with the supplied string value Usage: startsnotwith=hello -Does Not End With +# Does Not End With This validates that a string value does not end with the supplied string value Usage: endsnotwith=goodbye -International Standard Book Number +# International Standard Book Number This validates that a string value contains a valid isbn10 or isbn13 value. Usage: isbn -International Standard Book Number 10 +# International Standard Book Number 10 This validates that a string value contains a valid isbn10 value. Usage: isbn10 -International Standard Book Number 13 +# International Standard Book Number 13 This validates that a string value contains a valid isbn13 value. Usage: isbn13 -Universally Unique Identifier UUID +# Universally Unique Identifier UUID This validates that a string value contains a valid UUID. Uppercase UUID values will not pass - use `uuid_rfc4122` instead. Usage: uuid -Universally Unique Identifier UUID v3 +# Universally Unique Identifier UUID v3 This validates that a string value contains a valid version 3 UUID. Uppercase UUID values will not pass - use `uuid3_rfc4122` instead. Usage: uuid3 -Universally Unique Identifier UUID v4 +# Universally Unique Identifier UUID v4 This validates that a string value contains a valid version 4 UUID. Uppercase UUID values will not pass - use `uuid4_rfc4122` instead. Usage: uuid4 -Universally Unique Identifier UUID v5 +# Universally Unique Identifier UUID v5 This validates that a string value contains a valid version 5 UUID. Uppercase UUID values will not pass - use `uuid5_rfc4122` instead. Usage: uuid5 -Universally Unique Lexicographically Sortable Identifier ULID +# Universally Unique Lexicographically Sortable Identifier ULID This validates that a string value contains a valid ULID value. Usage: ulid -ASCII +# ASCII This validates that a string value contains only ASCII characters. NOTE: if the string is blank, this validates as true. Usage: ascii -Printable ASCII +# Printable ASCII This validates that a string value contains only printable ASCII characters. NOTE: if the string is blank, this validates as true. Usage: printascii -Multi-Byte Characters +# Multi-Byte Characters This validates that a string value contains one or more multibyte characters. NOTE: if the string is blank, this validates as true. Usage: multibyte -Data URL +# Data URL This validates that a string value contains a valid DataURI. NOTE: this will also validate that the data portion is valid base64 Usage: datauri -Latitude +# Latitude This validates that a string value contains a valid latitude. Usage: latitude -Longitude +# Longitude This validates that a string value contains a valid longitude. Usage: longitude -Social Security Number SSN +# Social Security Number SSN This validates that a string value contains a valid U.S. Social Security Number. Usage: ssn -Internet Protocol Address IP +# Internet Protocol Address IP This validates that a string value contains a valid IP Address. Usage: ip -Internet Protocol Address IPv4 +# Internet Protocol Address IPv4 This validates that a string value contains a valid v4 IP Address. Usage: ipv4 -Internet Protocol Address IPv6 +# Internet Protocol Address IPv6 This validates that a string value contains a valid v6 IP Address. Usage: ipv6 -Classless Inter-Domain Routing CIDR +# Classless Inter-Domain Routing CIDR This validates that a string value contains a valid CIDR Address. Usage: cidr -Classless Inter-Domain Routing CIDRv4 +# Classless Inter-Domain Routing CIDRv4 This validates that a string value contains a valid v4 CIDR Address. Usage: cidrv4 -Classless Inter-Domain Routing CIDRv6 +# Classless Inter-Domain Routing CIDRv6 This validates that a string value contains a valid v6 CIDR Address. Usage: cidrv6 -Transmission Control Protocol Address TCP +# Transmission Control Protocol Address TCP This validates that a string value contains a valid resolvable TCP Address. Usage: tcp_addr -Transmission Control Protocol Address TCPv4 +# Transmission Control Protocol Address TCPv4 This validates that a string value contains a valid resolvable v4 TCP Address. Usage: tcp4_addr -Transmission Control Protocol Address TCPv6 +# Transmission Control Protocol Address TCPv6 This validates that a string value contains a valid resolvable v6 TCP Address. Usage: tcp6_addr -User Datagram Protocol Address UDP +# User Datagram Protocol Address UDP This validates that a string value contains a valid resolvable UDP Address. Usage: udp_addr -User Datagram Protocol Address UDPv4 +# User Datagram Protocol Address UDPv4 This validates that a string value contains a valid resolvable v4 UDP Address. Usage: udp4_addr -User Datagram Protocol Address UDPv6 +# User Datagram Protocol Address UDPv6 This validates that a string value contains a valid resolvable v6 UDP Address. Usage: udp6_addr -Internet Protocol Address IP +# Internet Protocol Address IP This validates that a string value contains a valid resolvable IP Address. Usage: ip_addr -Internet Protocol Address IPv4 +# Internet Protocol Address IPv4 This validates that a string value contains a valid resolvable v4 IP Address. Usage: ip4_addr -Internet Protocol Address IPv6 +# Internet Protocol Address IPv6 This validates that a string value contains a valid resolvable v6 IP Address. Usage: ip6_addr -Unix domain socket end point Address +# Unix domain socket end point Address This validates that a string value contains a valid Unix Address. Usage: unix_addr -Media Access Control Address MAC +# Media Access Control Address MAC This validates that a string value contains a valid MAC Address. @@ -1199,13 +1220,13 @@ Note: See Go's ParseMAC for accepted formats and types: http://golang.org/src/net/mac.go?s=866:918#L29 -Hostname RFC 952 +# Hostname RFC 952 This validates that a string value is a valid Hostname according to RFC 952 https://tools.ietf.org/html/rfc952 Usage: hostname -Hostname RFC 1123 +# Hostname RFC 1123 This validates that a string value is a valid Hostname according to RFC 1123 https://tools.ietf.org/html/rfc1123 @@ -1217,28 +1238,28 @@ This validates that a string value contains a valid FQDN. Usage: fqdn -HTML Tags +# HTML Tags This validates that a string value appears to be an HTML element tag including those described at https://developer.mozilla.org/en-US/docs/Web/HTML/Element Usage: html -HTML Encoded +# HTML Encoded This validates that a string value is a proper character reference in decimal or hexadecimal format Usage: html_encoded -URL Encoded +# URL Encoded This validates that a string value is percent-encoded (URL encoded) according to https://tools.ietf.org/html/rfc3986#section-2.1 Usage: url_encoded -Directory +# Directory This validates that a string value contains a valid directory and that it exists on the machine. @@ -1246,42 +1267,54 @@ This is done using os.Stat, which is a platform independent function. Usage: dir -HostPort + +# Directory Path + +This validates that a string value contains a valid directory but does +not validate the existence of that directory. +This is done using os.Stat, which is a platform independent function. +It is safest to suffix the string with os.PathSeparator if the directory +may not exist at the time of validation. + + Usage: dirpath + + +# HostPort This validates that a string value contains a valid DNS hostname and port that can be used to valiate fields typically passed to sockets and connections. Usage: hostname_port -Datetime +# Datetime This validates that a string value is a valid datetime based on the supplied datetime format. Supplied format must match the official Go time format layout as documented in https://golang.org/pkg/time/ Usage: datetime=2006-01-02 -Iso3166-1 alpha-2 +# Iso3166-1 alpha-2 This validates that a string value is a valid country code based on iso3166-1 alpha-2 standard. see: https://www.iso.org/iso-3166-country-codes.html Usage: iso3166_1_alpha2 -Iso3166-1 alpha-3 +# Iso3166-1 alpha-3 This validates that a string value is a valid country code based on iso3166-1 alpha-3 standard. see: https://www.iso.org/iso-3166-country-codes.html Usage: iso3166_1_alpha3 -Iso3166-1 alpha-numeric +# Iso3166-1 alpha-numeric This validates that a string value is a valid country code based on iso3166-1 alpha-numeric standard. see: https://www.iso.org/iso-3166-country-codes.html Usage: iso3166_1_alpha3 -BCP 47 Language Tag +# BCP 47 Language Tag This validates that a string value is a valid BCP 47 language tag, as parsed by language.Parse. More information on https://pkg.go.dev/golang.org/x/text/language @@ -1295,14 +1328,14 @@ More information on https://www.iso.org/standard/60390.html Usage: bic -RFC 1035 label +# RFC 1035 label This validates that a string value is a valid dns RFC 1035 label, defined in RFC 1035. More information on https://datatracker.ietf.org/doc/html/rfc1035 Usage: dns_rfc1035_label -TimeZone +# TimeZone This validates that a string value is a valid time zone based on the time zone database present on the system. Although empty value and Local value are allowed by time.LoadLocation golang function, they are not allowed by this validator. @@ -1310,21 +1343,52 @@ More information on https://golang.org/pkg/time/#LoadLocation Usage: timezone -Semantic Version +# Semantic Version This validates that a string value is a valid semver version, defined in Semantic Versioning 2.0.0. More information on https://semver.org/ Usage: semver -Credit Card + +# CVE Identifier + +This validates that a string value is a valid cve id, defined in cve mitre. +More information on https://cve.mitre.org/ + + Usage: cve + + +# Credit Card This validates that a string value contains a valid credit card number using Luhn algoritm. Usage: credit_card + +# Luhn Checksum + + Usage: luhn_checksum + +This validates that a string or (u)int value contains a valid checksum using the Luhn algorithm. + + +#MongoDb ObjectID + +This validates that a string is a valid 24 character hexadecimal string. + + Usage: mongodb + + +# Cron + +This validates that a string value contains a valid cron expression. + + Usage: cron + Alias Validators and Tags +Alias Validators and Tags NOTE: When returning an error, the tag returned in "FieldError" will be the alias tag unless the dive tag is part of the alias. Everything after the dive tag is not reported as the alias tag. Also, the "ActualTag" in the before @@ -1354,7 +1418,7 @@ Validator notes: And the best reason, you can submit a pull request and we can keep on adding to the validation library of this package! -Non standard validators +# Non standard validators A collection of validation rules that are frequently needed but are more complex than the ones found in the baked in validators. @@ -1383,7 +1447,7 @@ Here is a list of the current non standard validators: Usage: notblank -Panics +# Panics This package panics when bad input is provided, this is by design, bad code like that should not make it to production. diff --git a/vendor/github.com/go-playground/validator/v10/errors.go b/vendor/github.com/go-playground/validator/v10/errors.go index 9a1b1abe..5856d57c 100644 --- a/vendor/github.com/go-playground/validator/v10/errors.go +++ b/vendor/github.com/go-playground/validator/v10/errors.go @@ -44,12 +44,9 @@ func (ve ValidationErrors) Error() string { buff := bytes.NewBufferString("") - var fe *fieldError - for i := 0; i < len(ve); i++ { - fe = ve[i].(*fieldError) - buff.WriteString(fe.Error()) + buff.WriteString(ve[i].Error()) buff.WriteString("\n") } diff --git a/vendor/github.com/go-playground/validator/v10/regexes.go b/vendor/github.com/go-playground/validator/v10/regexes.go index 9c1c6342..ba450b3d 100644 --- a/vendor/github.com/go-playground/validator/v10/regexes.go +++ b/vendor/github.com/go-playground/validator/v10/regexes.go @@ -19,6 +19,7 @@ const ( e164RegexString = "^\\+[1-9]?[0-9]{7,14}$" base64RegexString = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" base64URLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2}==|[A-Za-z0-9-_]{3}=|[A-Za-z0-9-_]{4})$" + base64RawURLRegexString = "^(?:[A-Za-z0-9-_]{4})*(?:[A-Za-z0-9-_]{2,4})$" iSBN10RegexString = "^(?:[0-9]{9}X|[0-9]{10})$" iSBN13RegexString = "^(?:(?:97(?:8|9))[0-9]{10})$" uUID3RegexString = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$" @@ -64,6 +65,9 @@ const ( bicRegexString = `^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$` semverRegexString = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` // numbered capture groups https://semver.org/ dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9]){0,62}$" + cveRegexString = `^CVE-(1999|2\d{3})-(0[^0]\d{2}|0\d[^0]\d{1}|0\d{2}[^0]|[1-9]{1}\d{3,})$` // CVE Format Id https://cve.mitre.org/cve/identifiers/syntaxchange.html + mongodbRegexString = "^[a-f\\d]{24}$" + cronRegexString = `(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})` ) var ( @@ -83,6 +87,7 @@ var ( emailRegex = regexp.MustCompile(emailRegexString) base64Regex = regexp.MustCompile(base64RegexString) base64URLRegex = regexp.MustCompile(base64URLRegexString) + base64RawURLRegex = regexp.MustCompile(base64RawURLRegexString) iSBN10Regex = regexp.MustCompile(iSBN10RegexString) iSBN13Regex = regexp.MustCompile(iSBN13RegexString) uUID3Regex = regexp.MustCompile(uUID3RegexString) @@ -118,8 +123,6 @@ var ( btcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32) btcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32) ethAddressRegex = regexp.MustCompile(ethAddressRegexString) - ethAddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString) - ethAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString) uRLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString) hTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString) hTMLRegex = regexp.MustCompile(hTMLRegexString) @@ -128,4 +131,7 @@ var ( bicRegex = regexp.MustCompile(bicRegexString) semverRegex = regexp.MustCompile(semverRegexString) dnsRegexRFC1035Label = regexp.MustCompile(dnsRegexStringRFC1035Label) + cveRegex = regexp.MustCompile(cveRegexString) + mongodbRegex = regexp.MustCompile(mongodbRegexString) + cronRegex = regexp.MustCompile(cronRegexString) ) diff --git a/vendor/github.com/go-playground/validator/v10/translations/en/en.go b/vendor/github.com/go-playground/validator/v10/translations/en/en.go index f007d342..486c95ec 100644 --- a/vendor/github.com/go-playground/validator/v10/translations/en/en.go +++ b/vendor/github.com/go-playground/validator/v10/translations/en/en.go @@ -1281,6 +1281,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er translation: "{0} must be a valid color", override: false, }, + { + tag: "cron", + translation: "{0} must be a valid cron expression", + override: false, + }, { tag: "oneof", translation: "{0} must be one of [{1}]", @@ -1361,6 +1366,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er translation: "{0} must be a valid boolean value", override: false, }, + { + tag: "cve", + translation: "{0} must be a valid cve identifier", + override: false, + }, } for _, t := range translations { diff --git a/vendor/github.com/go-playground/validator/v10/validator.go b/vendor/github.com/go-playground/validator/v10/validator.go index 80da095a..6f6d53ad 100644 --- a/vendor/github.com/go-playground/validator/v10/validator.go +++ b/vendor/github.com/go-playground/validator/v10/validator.go @@ -452,7 +452,6 @@ OUTER: v.ct = ct if !ct.fn(ctx, v) { - v.str1 = string(append(ns, cf.altName...)) if v.v.hasTagNameFunc { diff --git a/vendor/github.com/go-playground/validator/v10/validator_instance.go b/vendor/github.com/go-playground/validator/v10/validator_instance.go index 9493da49..51ae1aa0 100644 --- a/vendor/github.com/go-playground/validator/v10/validator_instance.go +++ b/vendor/github.com/go-playground/validator/v10/validator_instance.go @@ -190,14 +190,14 @@ func (v *Validate) ValidateMap(data map[string]interface{}, rules map[string]int // // eg. to use the names which have been specified for JSON representations of structs, rather than normal Go field names: // -// validate.RegisterTagNameFunc(func(fld reflect.StructField) string { -// name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0] -// // skip if tag key says it should be ignored -// if name == "-" { -// return "" -// } -// return name -// }) +// validate.RegisterTagNameFunc(func(fld reflect.StructField) string { +// name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0] +// // skip if tag key says it should be ignored +// if name == "-" { +// return "" +// } +// return name +// }) func (v *Validate) RegisterTagNameFunc(fn TagNameFunc) { v.tagNameFunc = fn v.hasTagNameFunc = true @@ -613,7 +613,7 @@ func (v *Validate) Var(field interface{}, tag string) error { } // VarCtx validates a single variable using tag style validation and allows passing of contextual -// validation validation information via context.Context. +// validation information via context.Context. // eg. // var i int // validate.Var(i, "gt=1,lt=10") @@ -632,6 +632,7 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e } ctag := v.fetchCacheTag(tag) + val := reflect.ValueOf(field) vd := v.pool.Get().(*validate) vd.top = val diff --git a/vendor/github.com/goccy/go-json/CHANGELOG.md b/vendor/github.com/goccy/go-json/CHANGELOG.md index 909b971e..d09bb89c 100644 --- a/vendor/github.com/goccy/go-json/CHANGELOG.md +++ b/vendor/github.com/goccy/go-json/CHANGELOG.md @@ -1,3 +1,13 @@ +# v0.10.2 - 2023/03/20 + +### New features + +* Support DebugDOT option for debugging encoder ( #440 ) + +### Fix bugs + +* Fix combination of embedding structure and omitempty option ( #442 ) + # v0.10.1 - 2023/03/13 ### Fix bugs diff --git a/vendor/github.com/goccy/go-json/internal/encoder/code.go b/vendor/github.com/goccy/go-json/internal/encoder/code.go index 66425a86..5b08faef 100644 --- a/vendor/github.com/goccy/go-json/internal/encoder/code.go +++ b/vendor/github.com/goccy/go-json/internal/encoder/code.go @@ -397,7 +397,7 @@ func (c *StructCode) lastFieldCode(field *StructFieldCode, firstField *Opcode) * func (c *StructCode) lastAnonymousFieldCode(firstField *Opcode) *Opcode { // firstField is special StructHead operation for anonymous structure. // So, StructHead's next operation is truly struct head operation. - for firstField.Op == OpStructHead { + for firstField.Op == OpStructHead || firstField.Op == OpStructField { firstField = firstField.Next } lastField := firstField diff --git a/vendor/github.com/goccy/go-json/internal/encoder/opcode.go b/vendor/github.com/goccy/go-json/internal/encoder/opcode.go index 05fc3ce0..df22f554 100644 --- a/vendor/github.com/goccy/go-json/internal/encoder/opcode.go +++ b/vendor/github.com/goccy/go-json/internal/encoder/opcode.go @@ -1,7 +1,9 @@ package encoder import ( + "bytes" "fmt" + "sort" "strings" "unsafe" @@ -555,6 +557,87 @@ func (c *Opcode) Dump() string { return strings.Join(codes, "\n") } +func (c *Opcode) DumpDOT() string { + type edge struct { + from, to *Opcode + label string + weight int + } + var edges []edge + + b := &bytes.Buffer{} + fmt.Fprintf(b, "digraph \"%p\" {\n", c.Type) + fmt.Fprintln(b, "mclimit=1.5;\nrankdir=TD;\nordering=out;\nnode[shape=box];") + for code := c; !code.IsEnd(); { + label := code.Op.String() + fmt.Fprintf(b, "\"%p\" [label=%q];\n", code, label) + if p := code.Next; p != nil { + edges = append(edges, edge{ + from: code, + to: p, + label: "Next", + weight: 10, + }) + } + if p := code.NextField; p != nil { + edges = append(edges, edge{ + from: code, + to: p, + label: "NextField", + weight: 2, + }) + } + if p := code.End; p != nil { + edges = append(edges, edge{ + from: code, + to: p, + label: "End", + weight: 1, + }) + } + if p := code.Jmp; p != nil { + edges = append(edges, edge{ + from: code, + to: p.Code, + label: "Jmp", + weight: 1, + }) + } + + switch code.Op.CodeType() { + case CodeSliceHead: + code = code.Next + case CodeMapHead: + code = code.Next + case CodeArrayElem, CodeSliceElem: + code = code.End + case CodeMapKey: + code = code.End + case CodeMapValue: + code = code.Next + case CodeMapEnd: + code = code.Next + case CodeStructField: + code = code.Next + case CodeStructEnd: + code = code.Next + default: + code = code.Next + } + if code.IsEnd() { + fmt.Fprintf(b, "\"%p\" [label=%q];\n", code, code.Op.String()) + } + } + sort.Slice(edges, func(i, j int) bool { + return edges[i].to.DisplayIdx < edges[j].to.DisplayIdx + }) + for _, e := range edges { + fmt.Fprintf(b, "\"%p\" -> \"%p\" [label=%q][weight=%d];\n", e.from, e.to, e.label, e.weight) + } + fmt.Fprint(b, "}") + return b.String() +} + func newSliceHeaderCode(ctx *compileContext, typ *runtime.Type) *Opcode { idx := opcodeOffset(ctx.ptrIndex) ctx.incPtrIndex() diff --git a/vendor/github.com/goccy/go-json/internal/encoder/option.go b/vendor/github.com/goccy/go-json/internal/encoder/option.go index 82d5ce3e..12c58e46 100644 --- a/vendor/github.com/goccy/go-json/internal/encoder/option.go +++ b/vendor/github.com/goccy/go-json/internal/encoder/option.go @@ -23,6 +23,7 @@ type Option struct { ColorScheme *ColorScheme Context context.Context DebugOut io.Writer + DebugDOTOut io.WriteCloser } type EncodeFormat struct { diff --git a/vendor/github.com/goccy/go-json/internal/encoder/vm/debug_vm.go b/vendor/github.com/goccy/go-json/internal/encoder/vm/debug_vm.go index fbbc0de4..82b6dd47 100644 --- a/vendor/github.com/goccy/go-json/internal/encoder/vm/debug_vm.go +++ b/vendor/github.com/goccy/go-json/internal/encoder/vm/debug_vm.go @@ -2,6 +2,7 @@ package vm import ( "fmt" + "io" "github.com/goccy/go-json/internal/encoder" ) @@ -14,6 +15,11 @@ func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) } else { code = codeSet.NoescapeKeyCode } + if wc := ctx.Option.DebugDOTOut; wc != nil { + _, _ = io.WriteString(wc, code.DumpDOT()) + wc.Close() + ctx.Option.DebugDOTOut = nil + } if err := recover(); err != nil { w := ctx.Option.DebugOut diff --git a/vendor/github.com/goccy/go-json/option.go b/vendor/github.com/goccy/go-json/option.go index af400a45..378031a0 100644 --- a/vendor/github.com/goccy/go-json/option.go +++ b/vendor/github.com/goccy/go-json/option.go @@ -48,6 +48,13 @@ func DebugWith(w io.Writer) EncodeOptionFunc { } } +// DebugDOT sets the destination to write opcodes graph. +func DebugDOT(w io.WriteCloser) EncodeOptionFunc { + return func(opt *EncodeOption) { + opt.DebugDOTOut = w + } +} + // Colorize add an identifier for coloring to the string of the encoded result. func Colorize(scheme *ColorScheme) EncodeOptionFunc { return func(opt *EncodeOption) { diff --git a/vendor/go.mongodb.org/mongo-driver/version/version.go b/vendor/go.mongodb.org/mongo-driver/version/version.go index 0264c03d..dd876312 100644 --- a/vendor/go.mongodb.org/mongo-driver/version/version.go +++ b/vendor/go.mongodb.org/mongo-driver/version/version.go @@ -8,4 +8,4 @@ package version // import "go.mongodb.org/mongo-driver/version" // Driver is the current version of the driver. -var Driver = "v1.11.2" +var Driver = "v1.11.3" diff --git a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/compression.go b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/compression.go index fa0dec7d..b0a03f1d 100644 --- a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/compression.go +++ b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/compression.go @@ -94,17 +94,17 @@ func DecompressPayload(in []byte, opts CompressionOpts) ([]byte, error) { } return uncompressed, nil case wiremessage.CompressorZstd: - w, err := zstd.NewReader(bytes.NewBuffer(in)) + r, err := zstd.NewReader(bytes.NewBuffer(in)) if err != nil { return nil, err } - defer w.Close() - var b bytes.Buffer - _, err = io.Copy(&b, w) + defer r.Close() + uncompressed := make([]byte, opts.UncompressedSize) + _, err = io.ReadFull(r, uncompressed) if err != nil { return nil, err } - return b.Bytes(), nil + return uncompressed, nil default: return nil, fmt.Errorf("unknown compressor ID %v", opts.Compressor) } diff --git a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation.go b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation.go index 4ff01c3d..385b1c24 100644 --- a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation.go +++ b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation.go @@ -433,10 +433,11 @@ func (op Operation) Execute(ctx context.Context) error { // size to 16MiB because that's the maximum wire message size supported by MongoDB. // // Comment copied from https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/fmt/print.go;l=147 - if cap(*wm) > 16*1024*1024 { - return + // + // Recycle byte slices that are smaller than 16MiB and at least half occupied. + if c := cap(*wm); c < 16*1024*1024 && c/2 < len(*wm) { + memoryPool.Put(wm) } - memoryPool.Put(wm) }() for { // If the server or connection are nil, try to select a new server and get a new connection. @@ -595,7 +596,7 @@ func (op Operation) Execute(ctx context.Context) error { if moreToCome { roundTrip = op.moreToComeRoundTrip } - res, *wm, err = roundTrip(ctx, conn, *wm) + res, err = roundTrip(ctx, conn, *wm) if ep, ok := srvr.(ErrorProcessor); ok { _ = ep.ProcessError(err, conn) @@ -855,18 +856,18 @@ func (op Operation) retryable(desc description.Server) bool { // roundTrip writes a wiremessage to the connection and then reads a wiremessage. The wm parameter // is reused when reading the wiremessage. -func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) (result, pooledSlice []byte, err error) { - err = conn.WriteWireMessage(ctx, wm) +func (op Operation) roundTrip(ctx context.Context, conn Connection, wm []byte) ([]byte, error) { + err := conn.WriteWireMessage(ctx, wm) if err != nil { - return nil, wm, op.networkError(err) + return nil, op.networkError(err) } - return op.readWireMessage(ctx, conn, wm) + return op.readWireMessage(ctx, conn) } -func (op Operation) readWireMessage(ctx context.Context, conn Connection, wm []byte) (result, pooledSlice []byte, err error) { - wm, err = conn.ReadWireMessage(ctx, wm[:0]) +func (op Operation) readWireMessage(ctx context.Context, conn Connection) (result []byte, err error) { + wm, err := conn.ReadWireMessage(ctx, nil) if err != nil { - return nil, wm, op.networkError(err) + return nil, op.networkError(err) } // If we're using a streamable connection, we set its streaming state based on the moreToCome flag in the server @@ -878,14 +879,11 @@ func (op Operation) readWireMessage(ctx context.Context, conn Connection, wm []b // decompress wiremessage wm, err = op.decompressWireMessage(wm) if err != nil { - return nil, wm, err + return nil, err } // decode - b, err := op.decodeResult(wm) - // Copy b to extend the lifetime. b may be a subslice of wm. wm will be added back to the memory pool and reused. - res := make([]byte, len(b)) - copy(res, b) + res, err := op.decodeResult(wm) // Update cluster/operation time and recovery tokens before handling the error to ensure we're properly updating // everything. op.updateClusterTimes(res) @@ -898,14 +896,14 @@ func (op Operation) readWireMessage(ctx context.Context, conn Connection, wm []b } if err != nil { - return res, wm, err + return res, err } // If there is no error, automatically attempt to decrypt all results if client side encryption is enabled. if op.Crypt != nil { res, err = op.Crypt.Decrypt(ctx, res) } - return res, wm, err + return res, err } // networkError wraps the provided error in an Error with label "NetworkError" and, if a transaction @@ -931,7 +929,7 @@ func (op Operation) networkError(err error) error { // moreToComeRoundTrip writes a wiremessage to the provided connection. This is used when an OP_MSG is // being sent with the moreToCome bit set. -func (op *Operation) moreToComeRoundTrip(ctx context.Context, conn Connection, wm []byte) (result, pooledSlice []byte, err error) { +func (op *Operation) moreToComeRoundTrip(ctx context.Context, conn Connection, wm []byte) (result []byte, err error) { err = conn.WriteWireMessage(ctx, wm) if err != nil { if op.Client != nil { @@ -939,7 +937,7 @@ func (op *Operation) moreToComeRoundTrip(ctx context.Context, conn Connection, w } err = Error{Message: err.Error(), Labels: []string{TransientTransactionError, NetworkError}, Wrapped: err} } - return bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "ok", 1)), wm, err + return bsoncore.BuildDocument(nil, bsoncore.AppendInt32Element(nil, "ok", 1)), err } // decompressWireMessage handles decompressing a wiremessage. If the wiremessage @@ -974,26 +972,13 @@ func (Operation) decompressWireMessage(wm []byte) ([]byte, error) { return nil, errors.New("malformed OP_COMPRESSED: insufficient bytes for compressed wiremessage") } - // Copy msg, which is a subslice of wm. wm will be used to store the return value of the decompressed message. - b := memoryPool.Get().(*[]byte) - msglen := len(msg) - if len(*b) < msglen { - *b = make([]byte, msglen) - } - copy(*b, msg) - defer func() { - memoryPool.Put(b) - }() - - if l := int(uncompressedSize) + 16; cap(wm) < l { - wm = make([]byte, 0, l) - } - wm = wiremessage.AppendHeader(wm[:0], uncompressedSize+16, reqid, respto, opcode) + wm = make([]byte, 0, int(uncompressedSize)+16) + wm = wiremessage.AppendHeader(wm, uncompressedSize+16, reqid, respto, opcode) opts := CompressionOpts{ Compressor: compressorID, UncompressedSize: uncompressedSize, } - uncompressed, err := DecompressPayload((*b)[0:msglen], opts) + uncompressed, err := DecompressPayload(msg, opts) if err != nil { return nil, err } diff --git a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation_exhaust.go b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation_exhaust.go index df7856b8..e0879de3 100644 --- a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation_exhaust.go +++ b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/operation_exhaust.go @@ -18,13 +18,7 @@ func (op Operation) ExecuteExhaust(ctx context.Context, conn StreamerConnection) return errors.New("exhaust read must be done with a connection that is currently streaming") } - wm := memoryPool.Get().(*[]byte) - defer func() { - memoryPool.Put(wm) - }() - var res []byte - var err error - res, *wm, err = op.readWireMessage(ctx, conn, (*wm)[:0]) + res, err := op.readWireMessage(ctx, conn) if err != nil { return err } diff --git a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/server.go b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/server.go index d416f6c1..03dea1bc 100644 --- a/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/server.go +++ b/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/server.go @@ -473,19 +473,11 @@ func (s *Server) update() { checkNow := s.checkNow done := s.done - var doneOnce bool defer func() { - if r := recover(); r != nil { - if doneOnce { - return - } - // We keep this goroutine alive attempting to read from the done channel. - <-done - } + _ = recover() }() closeServer := func() { - doneOnce = true s.subLock.Lock() for id, c := range s.subscribers { close(c) diff --git a/vendor/modules.txt b/vendor/modules.txt index e0d1c9e1..f7980cf1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -8,7 +8,7 @@ github.com/aliyun/aliyun-oss-go-sdk/oss ## explicit; go 1.16 github.com/allegro/bigcache/v3 github.com/allegro/bigcache/v3/queue -# github.com/baidubce/bce-sdk-go v0.9.144 +# github.com/baidubce/bce-sdk-go v0.9.146 ## explicit; go 1.11 github.com/baidubce/bce-sdk-go/auth github.com/baidubce/bce-sdk-go/bce @@ -80,7 +80,7 @@ github.com/go-playground/locales/zh # github.com/go-playground/universal-translator v0.18.1 ## explicit; go 1.18 github.com/go-playground/universal-translator -# github.com/go-playground/validator/v10 v10.11.2 +# github.com/go-playground/validator/v10 v10.12.0 ## explicit; go 1.18 github.com/go-playground/validator/v10 github.com/go-playground/validator/v10/translations/en @@ -88,7 +88,7 @@ github.com/go-playground/validator/v10/translations/zh # github.com/go-sql-driver/mysql v1.7.0 ## explicit; go 1.13 github.com/go-sql-driver/mysql -# github.com/goccy/go-json v0.10.1 +# github.com/goccy/go-json v0.10.2 ## explicit; go 1.12 github.com/goccy/go-json github.com/goccy/go-json/internal/decoder @@ -309,7 +309,7 @@ github.com/youmark/pkcs8 # github.com/yusufpapurcu/wmi v1.2.2 ## explicit; go 1.16 github.com/yusufpapurcu/wmi -# go.mongodb.org/mongo-driver v1.11.2 +# go.mongodb.org/mongo-driver v1.11.3 ## explicit; go 1.13 go.mongodb.org/mongo-driver/bson go.mongodb.org/mongo-driver/bson/bsoncodec