Last active
December 13, 2017 12:51
-
-
Save thinktainer/9167869d72f21ee9d79fe97b6d11684c to your computer and use it in GitHub Desktop.
replace_sql_credential.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"regexp" | |
"strings" | |
) | |
func main() { | |
rg := regexp.MustCompile(`.*:\/\/(\S+):(\S+)@.*`) | |
str := "sqlserver://user:password@host.example.com/?database=rootschema" | |
found := rg.FindStringSubmatchIndex(str) | |
res := str | |
for i := 2; i < len(found); i = i + 2 { | |
toRepl := string([]byte(str)[found[i]:found[i+1]]) | |
fmt.Println(toRepl) | |
res = strings.Replace(res, toRepl, "xxx", 1) | |
} | |
fmt.Println(res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment