mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Use strings.ReplaceAll and preallocate containers (#58483)
This commit is contained in:
parent
2dfe0a4060
commit
febcaeff3a
@ -14,7 +14,7 @@ func hello(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
safeBody := strings.Replace(string(body), "\n", "", -1)
|
safeBody := strings.ReplaceAll(string(body), "\n", "")
|
||||||
line := fmt.Sprintf("webbhook: -> %s", safeBody)
|
line := fmt.Sprintf("webbhook: -> %s", safeBody)
|
||||||
fmt.Println(line)
|
fmt.Println(line)
|
||||||
if _, err := io.WriteString(w, line); err != nil {
|
if _, err := io.WriteString(w, line); err != nil {
|
||||||
|
@ -32,8 +32,8 @@ func main() {
|
|||||||
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
safeSleep := strings.Replace(sleep.String(), "\n", "", -1)
|
safeSleep := strings.ReplaceAll(sleep.String(), "\n", "")
|
||||||
safeRequestUri := strings.Replace(r.RequestURI, "\n", "", -1)
|
safeRequestUri := strings.ReplaceAll(r.RequestURI, "\n", "")
|
||||||
log.Printf("sleeping for %s then proxying request: url '%s'", safeSleep, safeRequestUri)
|
log.Printf("sleeping for %s then proxying request: url '%s'", safeSleep, safeRequestUri)
|
||||||
|
|
||||||
// This is commented out as CodeQL flags this as vulnerability CWE-117 (https://cwe.mitre.org/data/definitions/117.html)
|
// This is commented out as CodeQL flags this as vulnerability CWE-117 (https://cwe.mitre.org/data/definitions/117.html)
|
||||||
|
@ -58,7 +58,7 @@ func LinuxPackageVersion(v string, buildID string) (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func shortenBuildID(buildID string) string {
|
func shortenBuildID(buildID string) string {
|
||||||
buildID = strings.Replace(buildID, "-", "", -1)
|
buildID = strings.ReplaceAll(buildID, "-", "")
|
||||||
if len(buildID) < 9 {
|
if len(buildID) < 9 {
|
||||||
return buildID
|
return buildID
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func (r RoleDTO) MarshalJSON() ([]byte, error) {
|
|||||||
func fallbackDisplayName(rName string) string {
|
func fallbackDisplayName(rName string) string {
|
||||||
// removing prefix for fixed roles
|
// removing prefix for fixed roles
|
||||||
rNameWithoutPrefix := strings.Replace(rName, FixedRolePrefix, "", 1)
|
rNameWithoutPrefix := strings.Replace(rName, FixedRolePrefix, "", 1)
|
||||||
return strings.TrimSpace(strings.Replace(rNameWithoutPrefix, ":", " ", -1))
|
return strings.TrimSpace(strings.ReplaceAll(rNameWithoutPrefix, ":", " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
type TeamRole struct {
|
type TeamRole struct {
|
||||||
|
@ -290,7 +290,7 @@ func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery
|
|||||||
suffix := refId
|
suffix := refId
|
||||||
if !validMetricDataID.MatchString(suffix) {
|
if !validMetricDataID.MatchString(suffix) {
|
||||||
newUUID := uuid.NewString()
|
newUUID := uuid.NewString()
|
||||||
suffix = strings.Replace(newUUID, "-", "", -1)
|
suffix = strings.ReplaceAll(newUUID, "-", "")
|
||||||
}
|
}
|
||||||
q.Id = fmt.Sprintf("query%s", suffix)
|
q.Id = fmt.Sprintf("query%s", suffix)
|
||||||
}
|
}
|
||||||
@ -436,8 +436,8 @@ func parseDimensions(dimensions map[string]interface{}) (map[string][]string, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sortDimensions(dimensions map[string][]string) map[string][]string {
|
func sortDimensions(dimensions map[string][]string) map[string][]string {
|
||||||
sortedDimensions := make(map[string][]string)
|
sortedDimensions := make(map[string][]string, len(dimensions))
|
||||||
var keys []string
|
keys := make([]string, 0, len(dimensions))
|
||||||
for k := range dimensions {
|
for k := range dimensions {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,8 @@ func getWildcards(pattern string) (string, []string) {
|
|||||||
|
|
||||||
// getRawPattern removes all regexp but keeps wildcards for building URL path.
|
// getRawPattern removes all regexp but keeps wildcards for building URL path.
|
||||||
func getRawPattern(rawPattern string) string {
|
func getRawPattern(rawPattern string) string {
|
||||||
rawPattern = strings.Replace(rawPattern, ":int", "", -1)
|
rawPattern = strings.ReplaceAll(rawPattern, ":int", "")
|
||||||
rawPattern = strings.Replace(rawPattern, ":string", "", -1)
|
rawPattern = strings.ReplaceAll(rawPattern, ":string", "")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
startIdx := strings.Index(rawPattern, "(")
|
startIdx := strings.Index(rawPattern, "(")
|
||||||
|
Loading…
Reference in New Issue
Block a user