mv more fkt to http-client

This commit is contained in:
Michael Jerger 2023-12-29 15:48:31 +01:00
parent 310d740cee
commit 587bd07372
2 changed files with 35 additions and 15 deletions

View file

@ -4,9 +4,7 @@
package utils
import (
"fmt"
"html"
"io"
"net/url"
"strings"
@ -30,15 +28,3 @@ func IsExternalURL(rawURL string) bool {
}
return false
}
// Limit number of characters in a string (useful to prevent log injection attacks and overly long log outputs)
// Thanks to https://www.socketloop.com/tutorials/golang-characters-limiter-example
func CharLimiter(s string, limit int) string {
reader := strings.NewReader(s)
buff := make([]byte, limit)
n, _ := io.ReadAtLeast(reader, buff, limit)
if n != 0 {
return fmt.Sprint(string(buff), "...")
}
return s
}