Created
August 28, 2020 12:08
-
-
Save ahmetozer/a4a18c1290ff0a9fc16d4b48edd94687 to your computer and use it in GitHub Desktop.
Golang String ini get value
This file contains hidden or 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" | |
"strings" | |
) | |
func getINI(iniText string, key string) string { | |
keyLoc := strings.Index(iniText, key) | |
if keyLoc == -1 { | |
return "" | |
} | |
newLineLoc := strings.Index(iniText[keyLoc:], "\n") | |
if newLineLoc == -1 { | |
return "" | |
} | |
keyLocAdjusted := keyLoc + len(key) | |
return iniText[keyLocAdjusted+1:keyLoc+newLineLoc] | |
} | |
func main() { | |
// Example string to parse. | |
test := `fl=197f3 | |
h=ahmetozer.org | |
ip=1.1.1.1 | |
ts=1598613384.494 | |
visit_scheme=http | |
uag=curl/7.55.1 | |
colo=SKG | |
http=http/1.1 | |
loc=TR | |
tls=off | |
sni=off | |
warp=off` | |
// Test between func. | |
fmt.Println(getINI(test, "fl")) | |
fmt.Println(getINI(test, "ip")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment