-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize code adjust #2700
Optimize code adjust #2700
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2700 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 41 41
Lines 2074 2074
=======================================
Hits 2047 2047
Misses 15 15
Partials 12 12
Continue to review full report at Codecov.
|
binding/form_mapping.go
Outdated
var ( | ||
errUnknownType = errors.New("unknown type") | ||
|
||
// ErrConvertMapStringSlice covert to map[string][]string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace covert to map[string][]string
with can not covert to map[string][]string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what you said, this is the error returned, as a developer using gin can know the error of the underlying transformation, rather than what you said not to let others know, which is a bad design
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ErrConvertMapStringSlice covert to map[string][]string
// ErrConvertToMapString can not convert to map[string]string
I don't know why the format can't be the same between ErrConvertMapStringSlice
and ErrConvertToMapString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that comment message.
errors.New("can not convert to map of strings")
comment message:
// can not convert to map[string]string
but
errors.New("can not convert to map slices of strings")
comment message:
// covert to map[string][]string
not
// can not convert to map[string][]string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if there are two errors here, they should be separated. As for the comment information you said, you can modify it appropriately. For the function point here, I hope the caller knows why the error occurred, instead of returning as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that comment message.
errors.New("can not convert to map of strings")comment message:
// can not convert to map[string]string
but
errors.New("can not convert to map slices of strings")comment message:
// covert to map[string][]string
not
// can not convert to map[string][]string
You can change the notes here. Thank you very much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to change the comment
-// ErrConvertMapStringSlice covert to map[string][]string
+// ErrConvertMapStringSlice can not covert to map[string][]string
ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings") | ||
|
||
// ErrConvertToMapString can not convert to map[string]string | ||
ErrConvertToMapString = errors.New("can not convert to map of strings") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not output var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an error in the conversion, it should be made known to the caller, not hidden in the current gin framework. I don't think your gin team has done a very good job of handling the error, and the way it is handled is not very friendly to the caller. I think there is something wrong with the design. Maybe more Go developers feel the same way.
If the previous proposal can be improved in the future, I will close this one. Thank you
Original ------------------
From: Bo-Yi Wu ***@***.***>
Date: Thu,Apr 29,2021 7:15 AM
To: gin-gonic/gin ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [gin-gonic/gin] Optimize code adjust (#2700)
Why created the other two PR #2709 and #2708 ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
There are two ways to deal with the previous error. I just extract the error from the above. You can see the previous processing. If the same error is the case, you can use an error variable.
…------------------ Original ------------------
From: Bo-Yi Wu ***@***.***>
Date: Thu,Apr 29,2021 10:46 AM
To: gin-gonic/gin ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [gin-gonic/gin] Optimize code adjust (#2700)
@appleboy commented on this pull request.
In binding/form_mapping.go:
> @@ -16,7 +16,15 @@ import ( "github.com/gin-gonic/gin/internal/json" ) -var errUnknownType = errors.New("unknown type") +var ( +errUnknownType = errors.New("unknown type") + +// ErrConvertMapStringSlice covert to map[string][]string // ErrConvertMapStringSlice covert to map[string][]string // ErrConvertToMapString can not convert to map[string]string
I don't know why the format can't be the same between ErrConvertMapStringSlice and ErrConvertToMapString?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
good,thanks,you can change it,no problem.
…------------------ Original ------------------
From: Bo-Yi Wu ***@***.***>
Date: Thu,Apr 29,2021 1:06 PM
To: gin-gonic/gin ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [gin-gonic/gin] Optimize code adjust (#2700)
@appleboy commented on this pull request.
In binding/form_mapping.go:
> @@ -16,7 +16,15 @@ import ( "github.com/gin-gonic/gin/internal/json" ) -var errUnknownType = errors.New("unknown type") +var ( +errUnknownType = errors.New("unknown type") + +// ErrConvertMapStringSlice covert to map[string][]string
I just want to change the comment
-// ErrConvertMapStringSlice covert to map[string][]string +// ErrConvertMapStringSlice can not covert to map[string][]string
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
done.
…------------------ Original ------------------
From: Bo-Yi Wu ***@***.***>
Date: Thu,Apr 29,2021 1:06 PM
To: gin-gonic/gin ***@***.***>
Cc: heige ***@***.***>, Author ***@***.***>
Subject: Re: [gin-gonic/gin] Optimize code adjust (#2700)
@appleboy commented on this pull request.
In binding/form_mapping.go:
> @@ -16,7 +16,15 @@ import ( "github.com/gin-gonic/gin/internal/json" ) -var errUnknownType = errors.New("unknown type") +var ( +errUnknownType = errors.New("unknown type") + +// ErrConvertMapStringSlice covert to map[string][]string
I just want to change the comment
-// ErrConvertMapStringSlice covert to map[string][]string +// ErrConvertMapStringSlice can not covert to map[string][]string
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
1.setFormMap error of result
2.adjust code for TrySet
3.error export for type multipart.FileHeader
4.code style adjust
5.reflect code maping optimize