You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/11/10 02:11:16 UTC

[GitHub] [dubbo-go] kedadiannao220 commented on a change in pull request #857: Fix Warnings: incorrect conversion between integer type

kedadiannao220 commented on a change in pull request #857:
URL: https://github.com/apache/dubbo-go/pull/857#discussion_r520240413



##########
File path: common/url.go
##########
@@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool {
 	return r
 }
 
-// GetParamInt gets int value by @key
+// GetParamInt gets int64 value by @key
 func (c URL) GetParamInt(key string, d int64) int64 {
-	r, err := strconv.Atoi(c.GetParam(key, ""))
+	r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 64)
 	if r == 0 || err != nil {
 		return d
 	}
-	return int64(r)
+	return r
+}
+
+// GetParamInt32 gets int32 value by @key
+func (c URL) GetParamInt32(key string, d int32) int32 {
+	r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 32)
+	if r == 0 || err != nil {

Review comment:
       `key` is only a flag of `param` value;  this conversion  is about value of  key, not key itself;
   
   e.g.
   ```
   func TestURLGetParamInt(t *testing.T) {
   	params := url.Values{}
   	params.Set("key", "3")
   	u := URL{baseUrl: baseUrl{params: params}}
   	v := u.GetParamInt("key", 1)
   	assert.Equal(t, int64(3), v)
   
   	u = URL{}
   	v = u.GetParamInt("key", 1)
   	assert.Equal(t, int64(1), v)
   }
   ``

##########
File path: common/url.go
##########
@@ -484,22 +484,49 @@ func (c URL) GetParamBool(key string, d bool) bool {
 	return r
 }
 
-// GetParamInt gets int value by @key
+// GetParamInt gets int64 value by @key
 func (c URL) GetParamInt(key string, d int64) int64 {
-	r, err := strconv.Atoi(c.GetParam(key, ""))
+	r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 64)
 	if r == 0 || err != nil {
 		return d
 	}
-	return int64(r)
+	return r
+}
+
+// GetParamInt32 gets int32 value by @key
+func (c URL) GetParamInt32(key string, d int32) int32 {
+	r, err := strconv.ParseInt(c.GetParam(key, ""), 10, 32)
+	if r == 0 || err != nil {

Review comment:
       `key` is only a flag of `param` value;  this conversion  is about value of  key, not key itself;
   
   e.g.
   ```
   func TestURLGetParamInt(t *testing.T) {
   	params := url.Values{}
   	params.Set("key", "3")
   	u := URL{baseUrl: baseUrl{params: params}}
   	v := u.GetParamInt("key", 1)
   	assert.Equal(t, int64(3), v)
   
   	u = URL{}
   	v = u.GetParamInt("key", 1)
   	assert.Equal(t, int64(1), v)
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org