-
Notifications
You must be signed in to change notification settings - Fork 55
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
Edit Naming for v2 Microsoft Teams Integration Endpoints #2722
Edit Naming for v2 Microsoft Teams Integration Endpoints #2722
Conversation
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/channel/{tenant_name}/{team_name}/{channel_name}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"tenant_name"+"}", _neturl.PathEscape(datadog.ParameterToString(tenantName, "")), -1) | ||
localVarPath = strings.Replace(localVarPath, "{"+"team_name"+"}", _neturl.PathEscape(datadog.ParameterToString(teamName, "")), -1) | ||
localVarPath = strings.Replace(localVarPath, "{"+"channel_name"+"}", _neturl.PathEscape(datadog.ParameterToString(channelName, "")), -1) |
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.
🟠 Code Quality Violation
localVarPath = strings.Replace(localVarPath, "{"+"channel_name"+"}", _neturl.PathEscape(datadog.ParameterToString(channelName, "")), -1) | |
localVarPath = strings.ReplaceAll(localVarPath, "{"+"channel_name"+"}", _neturl.PathEscape(datadog.ParameterToString(channelName, ""))) |
Do not call Replace with a negative limit, use ReplaceAll instead (...read more)
In Go, the strings.Replace()
function is used to replace a certain substring within a string with another substring. The function takes in four parameters: the original string, the old substring to be replaced, the new substring that will replace the old one, and an integer limit dictating how many replacements to be made.
Calling strings.Replace()
with a negative limit doesn't really make sense. According to the Go documentation, if limit is negative, there is no limit on the number of replacements. Which means it will replace all instances of old substring in the original string with a new substring.
For example:
fmt.Println(strings.Replace("oink oink oink", "k", "ky", -2))
In this example, Replace returns a copy of the string "oink oink oink" where "k" is replaced by "ky" everywhere it appears, because limit is -2.
So it's not necessarily "incorrect" to use a negative limit, but it can create misunderstandings in your code. It's best to use a limit of -1
when you want to replace all instances, as this convention is more commonly understood to mean "no limit".
But if you specifically want to avoid using negative limit for Replace or looking for replace method with better efficiency, using strings.NewReplacer()
could be a better option when there are multiple string pairs need to be replaced, where you can specify a list of old-new string pairs.
Or you can use strings.ReplaceAll()
. It is equivalent to Replace with a limit of -1
. It's arguably clearer and more self-explanatory than using a negative limit with strings.Replace()
.
For example:
fmt.Println(strings.ReplaceAll("oink oink oink", "o", "ky"))
It replaces all instances of "o" in the string "oink oink oink" by "ky".
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/tenant-based-handles/{handle_id}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"handle_id"+"}", _neturl.PathEscape(datadog.ParameterToString(handleId, "")), -1) | ||
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/channel/{tenant_name}/{team_name}/{channel_name}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"tenant_name"+"}", _neturl.PathEscape(datadog.ParameterToString(tenantName, "")), -1) |
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.
🟠 Code Quality Violation
localVarPath = strings.Replace(localVarPath, "{"+"tenant_name"+"}", _neturl.PathEscape(datadog.ParameterToString(tenantName, "")), -1) | |
localVarPath = strings.ReplaceAll(localVarPath, "{"+"tenant_name"+"}", _neturl.PathEscape(datadog.ParameterToString(tenantName, ""))) |
Do not call Replace with a negative limit, use ReplaceAll instead (...read more)
In Go, the strings.Replace()
function is used to replace a certain substring within a string with another substring. The function takes in four parameters: the original string, the old substring to be replaced, the new substring that will replace the old one, and an integer limit dictating how many replacements to be made.
Calling strings.Replace()
with a negative limit doesn't really make sense. According to the Go documentation, if limit is negative, there is no limit on the number of replacements. Which means it will replace all instances of old substring in the original string with a new substring.
For example:
fmt.Println(strings.Replace("oink oink oink", "k", "ky", -2))
In this example, Replace returns a copy of the string "oink oink oink" where "k" is replaced by "ky" everywhere it appears, because limit is -2.
So it's not necessarily "incorrect" to use a negative limit, but it can create misunderstandings in your code. It's best to use a limit of -1
when you want to replace all instances, as this convention is more commonly understood to mean "no limit".
But if you specifically want to avoid using negative limit for Replace or looking for replace method with better efficiency, using strings.NewReplacer()
could be a better option when there are multiple string pairs need to be replaced, where you can specify a list of old-new string pairs.
Or you can use strings.ReplaceAll()
. It is equivalent to Replace with a limit of -1
. It's arguably clearer and more self-explanatory than using a negative limit with strings.Replace()
.
For example:
fmt.Println(strings.ReplaceAll("oink oink oink", "o", "ky"))
It replaces all instances of "o" in the string "oink oink oink" by "ky".
localVarPath = strings.Replace(localVarPath, "{"+"handle_id"+"}", _neturl.PathEscape(datadog.ParameterToString(handleId, "")), -1) | ||
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/channel/{tenant_name}/{team_name}/{channel_name}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"tenant_name"+"}", _neturl.PathEscape(datadog.ParameterToString(tenantName, "")), -1) | ||
localVarPath = strings.Replace(localVarPath, "{"+"team_name"+"}", _neturl.PathEscape(datadog.ParameterToString(teamName, "")), -1) |
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.
🟠 Code Quality Violation
localVarPath = strings.Replace(localVarPath, "{"+"team_name"+"}", _neturl.PathEscape(datadog.ParameterToString(teamName, "")), -1) | |
localVarPath = strings.ReplaceAll(localVarPath, "{"+"team_name"+"}", _neturl.PathEscape(datadog.ParameterToString(teamName, ""))) |
Do not call Replace with a negative limit, use ReplaceAll instead (...read more)
In Go, the strings.Replace()
function is used to replace a certain substring within a string with another substring. The function takes in four parameters: the original string, the old substring to be replaced, the new substring that will replace the old one, and an integer limit dictating how many replacements to be made.
Calling strings.Replace()
with a negative limit doesn't really make sense. According to the Go documentation, if limit is negative, there is no limit on the number of replacements. Which means it will replace all instances of old substring in the original string with a new substring.
For example:
fmt.Println(strings.Replace("oink oink oink", "k", "ky", -2))
In this example, Replace returns a copy of the string "oink oink oink" where "k" is replaced by "ky" everywhere it appears, because limit is -2.
So it's not necessarily "incorrect" to use a negative limit, but it can create misunderstandings in your code. It's best to use a limit of -1
when you want to replace all instances, as this convention is more commonly understood to mean "no limit".
But if you specifically want to avoid using negative limit for Replace or looking for replace method with better efficiency, using strings.NewReplacer()
could be a better option when there are multiple string pairs need to be replaced, where you can specify a list of old-new string pairs.
Or you can use strings.ReplaceAll()
. It is equivalent to Replace with a limit of -1
. It's arguably clearer and more self-explanatory than using a negative limit with strings.Replace()
.
For example:
fmt.Println(strings.ReplaceAll("oink oink oink", "o", "ky"))
It replaces all instances of "o" in the string "oink oink oink" by "ky".
62070c3
to
4987614
Compare
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/tenant-based-handles/name/{handle_name}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"handle_name"+"}", _neturl.PathEscape(datadog.ParameterToString(handleName, "")), -1) | ||
localVarPath := localBasePath + "/api/v2/integration/ms-teams/configuration/tenant-based-handles/{handle_id}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"handle_id"+"}", _neturl.PathEscape(datadog.ParameterToString(handleId, "")), -1) |
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.
🟠 Code Quality Violation
localVarPath = strings.Replace(localVarPath, "{"+"handle_id"+"}", _neturl.PathEscape(datadog.ParameterToString(handleId, "")), -1) | |
localVarPath = strings.ReplaceAll(localVarPath, "{"+"handle_id"+"}", _neturl.PathEscape(datadog.ParameterToString(handleId, ""))) |
Do not call Replace with a negative limit, use ReplaceAll instead (...read more)
In Go, the strings.Replace()
function is used to replace a certain substring within a string with another substring. The function takes in four parameters: the original string, the old substring to be replaced, the new substring that will replace the old one, and an integer limit dictating how many replacements to be made.
Calling strings.Replace()
with a negative limit doesn't really make sense. According to the Go documentation, if limit is negative, there is no limit on the number of replacements. Which means it will replace all instances of old substring in the original string with a new substring.
For example:
fmt.Println(strings.Replace("oink oink oink", "k", "ky", -2))
In this example, Replace returns a copy of the string "oink oink oink" where "k" is replaced by "ky" everywhere it appears, because limit is -2.
So it's not necessarily "incorrect" to use a negative limit, but it can create misunderstandings in your code. It's best to use a limit of -1
when you want to replace all instances, as this convention is more commonly understood to mean "no limit".
But if you specifically want to avoid using negative limit for Replace or looking for replace method with better efficiency, using strings.NewReplacer()
could be a better option when there are multiple string pairs need to be replaced, where you can specify a list of old-new string pairs.
Or you can use strings.ReplaceAll()
. It is equivalent to Replace with a limit of -1
. It's arguably clearer and more self-explanatory than using a negative limit with strings.Replace()
.
For example:
fmt.Println(strings.ReplaceAll("oink oink oink", "o", "ky"))
It replaces all instances of "o" in the string "oink oink oink" by "ky".
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com> e41fca5
See DataDog/datadog-api-spec#3165
Test branch datadog-api-spec/test/kalil.black/CHATINTS-383/ms-teams-api-spec-refactor