Improved parameter parsing

This commit is contained in:
Pijus Kamandulis
2020-01-21 23:46:30 +02:00
parent 320e044f3c
commit 6e0e39ada2
4 changed files with 93 additions and 43 deletions

View File

@@ -4,6 +4,8 @@ import (
"flag"
"fmt"
"os"
"regexp"
"strings"
)
// Config - Runtime configuration
@@ -32,3 +34,17 @@ func GetConfig() {
Config.Debug = *debug
Config.MetaData = *metadata
}
// GetUsername - Get's username from passed URL param
func GetUsername() string {
if match := strings.Contains(Config.URL, "/"); !match { // Not url
return strings.Replace(Config.URL, "@", "", -1)
}
if match, _ := regexp.MatchString(".+tiktok\\.com/@.+", Config.URL); match { // URL
stripedSuffix := strings.Split(Config.URL, "@")[1]
return strings.Split(stripedSuffix, "/")[0]
}
panic("Could not recognise URL format")
}