From b783cedb39b2c90dd4127e79e42a66f4285d0050 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 14 Jan 2024 22:24:03 +0000 Subject: [PATCH] Bump the go group with 2 updates Bumps the go group with 2 updates: [github.com/ggicci/httpin](https://github.com/ggicci/httpin) and [github.com/go-playground/validator/v10](https://github.com/go-playground/validator). Updates `github.com/ggicci/httpin` from 0.15.2 to 0.15.3 - [Release notes](https://github.com/ggicci/httpin/releases) - [Commits](https://github.com/ggicci/httpin/compare/v0.15.2...v0.15.3) Updates `github.com/go-playground/validator/v10` from 10.16.0 to 10.17.0 - [Release notes](https://github.com/go-playground/validator/releases) - [Commits](https://github.com/go-playground/validator/compare/v10.16.0...v10.17.0) --- updated-dependencies: - dependency-name: github.com/ggicci/httpin dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go - dependency-name: github.com/go-playground/validator/v10 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go ... Signed-off-by: dependabot[bot] --- go.mod | 4 +- go.sum | 8 +- vendor/github.com/ggicci/httpin/.gitignore | 1 + vendor/github.com/ggicci/httpin/core/body.go | 7 +- vendor/github.com/ggicci/httpin/core/core.go | 2 +- vendor/github.com/ggicci/httpin/core/file.go | 9 -- .../ggicci/httpin/core/requestbuilder.go | 83 ++++++++++++------- .../go-playground/validator/v10/README.md | 2 +- .../go-playground/validator/v10/errors.go | 8 +- vendor/modules.txt | 4 +- 10 files changed, 73 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index 406531c5..b0a15fe8 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/SongStitch/go-webp v1.2.0 github.com/fogleman/gg v1.3.0 - github.com/ggicci/httpin v0.15.2 - github.com/go-playground/validator/v10 v10.16.0 + github.com/ggicci/httpin v0.15.3 + github.com/go-playground/validator/v10 v10.17.0 github.com/joho/godotenv v1.5.1 github.com/justinas/alice v1.2.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 diff --git a/go.sum b/go.sum index e1fbed98..d1b63d1e 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/ggicci/httpin v0.15.2 h1:UqhjJ0vJgdUCr2eemoCG/VBtwtU3OG72Nao5p1s5gTU= -github.com/ggicci/httpin v0.15.2/go.mod h1:whE/5nx1jCp//UQ6rgNpq2WNxOr9FV0OpxMnQQC0Xvs= +github.com/ggicci/httpin v0.15.3 h1:oDq5GDA+NN2mszOC6Ms2m9KNoyHqRlh1NvGJaXBCNvE= +github.com/ggicci/httpin v0.15.3/go.mod h1:whE/5nx1jCp//UQ6rgNpq2WNxOr9FV0OpxMnQQC0Xvs= github.com/ggicci/owl v0.7.0 h1:+AMlCR0AY7j72q7hjtN4pm8VJiikwpROtMgvPnXtuik= github.com/ggicci/owl v0.7.0/go.mod h1:TRPWshRwYej6uES//YW5aNgLB370URwyta1Ytfs7KXs= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= @@ -23,8 +23,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= 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.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= -github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74= +github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= diff --git a/vendor/github.com/ggicci/httpin/.gitignore b/vendor/github.com/ggicci/httpin/.gitignore index b6aac0a9..f0d62645 100644 --- a/vendor/github.com/ggicci/httpin/.gitignore +++ b/vendor/github.com/ggicci/httpin/.gitignore @@ -18,3 +18,4 @@ # Project specified .DS_Store __debug* +docs/ \ No newline at end of file diff --git a/vendor/github.com/ggicci/httpin/core/body.go b/vendor/github.com/ggicci/httpin/core/body.go index 4fe3638e..b33a4fb2 100644 --- a/vendor/github.com/ggicci/httpin/core/body.go +++ b/vendor/github.com/ggicci/httpin/core/body.go @@ -15,6 +15,9 @@ import ( "github.com/ggicci/httpin/internal" ) +// ErrUnknownBodyFormat is returned when a serializer for the specified body format has not been specified. +var ErrUnknownBodyFormat = errors.New("unknown body format") + // DirectiveBody is the implementation of the "body" directive. type DirectiveBody struct{} @@ -22,7 +25,7 @@ func (db *DirectiveBody) Decode(rtm *DirectiveRuntime) error { req := rtm.GetRequest() bodyFormat, bodySerializer := db.getSerializer(rtm) if bodySerializer == nil { - return fmt.Errorf("unknown body format: %q", bodyFormat) + return fmt.Errorf("%w: %q", ErrUnknownBodyFormat, bodyFormat) } if err := bodySerializer.Decode(req.Body, rtm.Value.Elem().Addr().Interface()); err != nil { return err @@ -33,7 +36,7 @@ func (db *DirectiveBody) Decode(rtm *DirectiveRuntime) error { func (db *DirectiveBody) Encode(rtm *DirectiveRuntime) error { bodyFormat, bodySerializer := db.getSerializer(rtm) if bodySerializer == nil { - return fmt.Errorf("unknown body format: %q", bodyFormat) + return fmt.Errorf("%w: %q", ErrUnknownBodyFormat, bodyFormat) } if bodyReader, err := bodySerializer.Encode(rtm.Value.Interface()); err != nil { return err diff --git a/vendor/github.com/ggicci/httpin/core/core.go b/vendor/github.com/ggicci/httpin/core/core.go index afa7d007..c6ce81b0 100644 --- a/vendor/github.com/ggicci/httpin/core/core.go +++ b/vendor/github.com/ggicci/httpin/core/core.go @@ -108,7 +108,7 @@ func (c *Core) NewRequestWithContext(ctx context.Context, method string, url str return nil, err } - rb := NewRequestBuilder() + rb := NewRequestBuilder(ctx) // NOTE(ggicci): the error returned a joined error by using errors.Join. if err = c.scanResolver.Scan( diff --git a/vendor/github.com/ggicci/httpin/core/file.go b/vendor/github.com/ggicci/httpin/core/file.go index ae83322f..b036e139 100644 --- a/vendor/github.com/ggicci/httpin/core/file.go +++ b/vendor/github.com/ggicci/httpin/core/file.go @@ -61,15 +61,6 @@ func (f *File) UnmarshalFile(fh FileHeader) error { return nil } -// Encode implements FileEncoder. -// func (f File) Encode() (string, io.ReadCloser, error) { -// uploadReader, err := f.OpenUploadStream() -// if err != nil { -// return "", nil, err -// } -// return f.Filename(), uploadReader, nil -// } - // IsUpload returns true when the File instance is created for an upload purpose. // Typically, you should use UploadFilename or UploadReader to create a File instance // for upload. diff --git a/vendor/github.com/ggicci/httpin/core/requestbuilder.go b/vendor/github.com/ggicci/httpin/core/requestbuilder.go index 22f4c7cf..f328b502 100644 --- a/vendor/github.com/ggicci/httpin/core/requestbuilder.go +++ b/vendor/github.com/ggicci/httpin/core/requestbuilder.go @@ -1,7 +1,7 @@ package core import ( - "bytes" + "context" "errors" "fmt" "io" @@ -21,9 +21,10 @@ type RequestBuilder struct { Path map[string]string // placeholder: value BodyType string // json, xml, etc. Body io.ReadCloser + ctx context.Context } -func NewRequestBuilder() *RequestBuilder { +func NewRequestBuilder(ctx context.Context) *RequestBuilder { return &RequestBuilder{ Query: make(url.Values), Form: make(url.Values), @@ -31,6 +32,7 @@ func NewRequestBuilder() *RequestBuilder { Header: make(http.Header), Cookie: make([]*http.Cookie, 0), Path: make(map[string]string), + ctx: ctx, } } @@ -149,41 +151,58 @@ func (rb *RequestBuilder) populateForm(req *http.Request) { } func (rb *RequestBuilder) populateMultipartForm(req *http.Request) error { - body := new(bytes.Buffer) - writer := multipart.NewWriter(body) - - // Populate the form fields. - for k, v := range rb.Form { - for _, sv := range v { - fieldWriter, _ := writer.CreateFormField(k) - fieldWriter.Write([]byte(sv)) - } - } - - // Populate the attachments. - for key, files := range rb.Attachment { - for i, file := range files { - filename := file.Filename() - contentReader, err := file.MarshalFile() - filename = normalizeUploadFilename(key, filename, i) - - if err != nil { - return fmt.Errorf("upload %s %q failed: %w", key, filename, err) + // Create a pipe and a multipart writer. + pr, pw := io.Pipe() + writer := multipart.NewWriter(pw) + + // Write the multipart form data to the pipe in a separate goroutine. + go func() { + defer pw.Close() + defer writer.Close() + + // Populate the form fields. + for k, v := range rb.Form { + for _, sv := range v { + select { + case <-rb.ctx.Done(): + pw.CloseWithError(rb.ctx.Err()) + return + default: + fieldWriter, _ := writer.CreateFormField(k) + fieldWriter.Write([]byte(sv)) + } } + } - fileWriter, _ := writer.CreateFormFile(key, filename) - if _, err = io.Copy(fileWriter, contentReader); err != nil { - return fmt.Errorf("upload %s %q failed: %w", key, filename, err) + // Populate the attachments. + for key, files := range rb.Attachment { + for i, file := range files { + select { + case <-rb.ctx.Done(): + pw.CloseWithError(rb.ctx.Err()) + return + default: + filename := file.Filename() + contentReader, err := file.MarshalFile() + filename = normalizeUploadFilename(key, filename, i) + + if err != nil { + pw.CloseWithError(fmt.Errorf("upload %s %q failed: %w", key, filename, err)) + return + } + + fileWriter, _ := writer.CreateFormFile(key, filename) + if _, err = io.Copy(fileWriter, contentReader); err != nil { + pw.CloseWithError(fmt.Errorf("upload %s %q failed: %w", key, filename, err)) + return + } + } } } - } - - if err := writer.Close(); err != nil { - return fmt.Errorf("close multipart writer: %w", err) - } + }() - // Set the body and content type. - req.Body = io.NopCloser(body) + // Set the body to the read end of the pipe and the content type. + req.Body = io.NopCloser(pr) rb.Header.Set("Content-Type", writer.FormDataContentType()) return nil } diff --git a/vendor/github.com/go-playground/validator/v10/README.md b/vendor/github.com/go-playground/validator/v10/README.md index dbbafc3e..810097b3 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.16.0-green.svg) +![Project status](https://img.shields.io/badge/version-10.17.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) diff --git a/vendor/github.com/go-playground/validator/v10/errors.go b/vendor/github.com/go-playground/validator/v10/errors.go index 5856d57c..be2676e9 100644 --- a/vendor/github.com/go-playground/validator/v10/errors.go +++ b/vendor/github.com/go-playground/validator/v10/errors.go @@ -257,15 +257,19 @@ func (fe *fieldError) Error() string { // NOTE: if no registered translation can be found, it returns the original // untranslated error message. func (fe *fieldError) Translate(ut ut.Translator) string { + var fn TranslationFunc m, ok := fe.v.transTagFunc[ut] if !ok { return fe.Error() } - fn, ok := m[fe.tag] + fn, ok = m[fe.tag] if !ok { - return fe.Error() + fn, ok = m[fe.actualTag] + if !ok { + return fe.Error() + } } return fn(ut, fe) diff --git a/vendor/modules.txt b/vendor/modules.txt index 02516ba4..469845e2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,7 +19,7 @@ github.com/gabriel-vasile/mimetype github.com/gabriel-vasile/mimetype/internal/charset github.com/gabriel-vasile/mimetype/internal/json github.com/gabriel-vasile/mimetype/internal/magic -# github.com/ggicci/httpin v0.15.2 +# github.com/ggicci/httpin v0.15.3 ## explicit; go 1.20 github.com/ggicci/httpin github.com/ggicci/httpin/core @@ -34,7 +34,7 @@ github.com/go-playground/locales/currency # 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.16.0 +# github.com/go-playground/validator/v10 v10.17.0 ## explicit; go 1.18 github.com/go-playground/validator/v10 # github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0