mirror of https://github.com/grafana/grafana.git
				
				
				
			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 | ||||
| 	} | ||||
| 
 | ||||
| 	safeBody := strings.Replace(string(body), "\n", "", -1) | ||||
| 	safeBody := strings.ReplaceAll(string(body), "\n", "") | ||||
| 	line := fmt.Sprintf("webbhook: -> %s", safeBody) | ||||
| 	fmt.Println(line) | ||||
| 	if _, err := io.WriteString(w, line); err != nil { | ||||
|  |  | |||
|  | @ -32,8 +32,8 @@ func main() { | |||
| 	proxy := httputil.NewSingleHostReverseProxy(originURL) | ||||
| 
 | ||||
| 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||||
| 		safeSleep := strings.Replace(sleep.String(), "\n", "", -1) | ||||
| 		safeRequestUri := strings.Replace(r.RequestURI, "\n", "", -1) | ||||
| 		safeSleep := strings.ReplaceAll(sleep.String(), "\n", "") | ||||
| 		safeRequestUri := strings.ReplaceAll(r.RequestURI, "\n", "") | ||||
| 		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)
 | ||||
|  |  | |||
|  | @ -58,7 +58,7 @@ func LinuxPackageVersion(v string, buildID string) (string, string) { | |||
| } | ||||
| 
 | ||||
| func shortenBuildID(buildID string) string { | ||||
| 	buildID = strings.Replace(buildID, "-", "", -1) | ||||
| 	buildID = strings.ReplaceAll(buildID, "-", "") | ||||
| 	if len(buildID) < 9 { | ||||
| 		return buildID | ||||
| 	} | ||||
|  |  | |||
|  | @ -165,7 +165,7 @@ func (r RoleDTO) MarshalJSON() ([]byte, error) { | |||
| func fallbackDisplayName(rName string) string { | ||||
| 	// removing prefix for fixed roles
 | ||||
| 	rNameWithoutPrefix := strings.Replace(rName, FixedRolePrefix, "", 1) | ||||
| 	return strings.TrimSpace(strings.Replace(rNameWithoutPrefix, ":", " ", -1)) | ||||
| 	return strings.TrimSpace(strings.ReplaceAll(rNameWithoutPrefix, ":", " ")) | ||||
| } | ||||
| 
 | ||||
| type TeamRole struct { | ||||
|  |  | |||
|  | @ -290,7 +290,7 @@ func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery | |||
| 		suffix := refId | ||||
| 		if !validMetricDataID.MatchString(suffix) { | ||||
| 			newUUID := uuid.NewString() | ||||
| 			suffix = strings.Replace(newUUID, "-", "", -1) | ||||
| 			suffix = strings.ReplaceAll(newUUID, "-", "") | ||||
| 		} | ||||
| 		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 { | ||||
| 	sortedDimensions := make(map[string][]string) | ||||
| 	var keys []string | ||||
| 	sortedDimensions := make(map[string][]string, len(dimensions)) | ||||
| 	keys := make([]string, 0, len(dimensions)) | ||||
| 	for k := range dimensions { | ||||
| 		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.
 | ||||
| func getRawPattern(rawPattern string) string { | ||||
| 	rawPattern = strings.Replace(rawPattern, ":int", "", -1) | ||||
| 	rawPattern = strings.Replace(rawPattern, ":string", "", -1) | ||||
| 	rawPattern = strings.ReplaceAll(rawPattern, ":int", "") | ||||
| 	rawPattern = strings.ReplaceAll(rawPattern, ":string", "") | ||||
| 
 | ||||
| 	for { | ||||
| 		startIdx := strings.Index(rawPattern, "(") | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue