Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Created August 28, 2020 12:08
Show Gist options
  • Save ahmetozer/a4a18c1290ff0a9fc16d4b48edd94687 to your computer and use it in GitHub Desktop.
Save ahmetozer/a4a18c1290ff0a9fc16d4b48edd94687 to your computer and use it in GitHub Desktop.
Golang String ini get value
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