| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package utils |
||
| 2 | |||
| 3 | import "strings" |
||
| 4 | |||
| 5 | func CenterString(str string, width int) string { |
||
| 6 | spaces := int(float64(width-len(str)) / 2) |
||
| 7 | // If the string is longer than the width, return the string as is |
||
| 8 | if spaces < 0 { |
||
| 9 | return str |
||
| 10 | } |
||
| 11 | return strings.Repeat(" ", spaces) + str + strings.Repeat(" ", width-(spaces+len(str))) |
||
| 12 | } |
||
| 13 | |||
| 14 | // ObscureToken Obscure a token by replacing the middle characters with "..." |
||
| 15 | func ObscureToken(token string) string { |
||
| 16 | if len(token) < 8 { |
||
| 17 | return token |
||
| 18 | } |
||
| 19 | return token[:14] + "..." + token[len(token)-4:] |
||
| 20 | } |
||
| 21 |