fix regex
This commit is contained in:
parent
47ab0080e7
commit
b714c1b463
11
main.go
11
main.go
@ -31,20 +31,15 @@ type Userinfo struct {
|
|||||||
|
|
||||||
func Dedup(input string) string {
|
func Dedup(input string) string {
|
||||||
unique := []string{}
|
unique := []string{}
|
||||||
|
|
||||||
words := strings.Split(input, " ")
|
words := strings.Split(input, " ")
|
||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
// If we alredy have this word, skip.
|
|
||||||
if contains(unique, word) {
|
if contains(unique, word) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
unique = append(unique, word)
|
unique = append(unique, word)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(unique, " ")
|
return strings.Join(unique, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(strs []string, str string) bool {
|
func contains(strs []string, str string) bool {
|
||||||
for _, s := range strs {
|
for _, s := range strs {
|
||||||
if s == str {
|
if s == str {
|
||||||
@ -58,9 +53,7 @@ func userdata(username, usersonline string) Userinfo {
|
|||||||
filename := "/home/" + username + "/meta-info.env"
|
filename := "/home/" + username + "/meta-info.env"
|
||||||
_, error := os.Stat(filename)
|
_, error := os.Stat(filename)
|
||||||
regex := "(^| )" + username + "($| )"
|
regex := "(^| )" + username + "($| )"
|
||||||
log.Info(usersonline)
|
|
||||||
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
||||||
log.Info(isonline)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
@ -132,13 +125,11 @@ func main() {
|
|||||||
userstr := string(users)
|
userstr := string(users)
|
||||||
userstr2 := strings.TrimSuffix(userstr, "\n")
|
userstr2 := strings.TrimSuffix(userstr, "\n")
|
||||||
usersarr := strings.Split(userstr2, "\n")
|
usersarr := strings.Split(userstr2, "\n")
|
||||||
//var userinfoarr []interface{}
|
|
||||||
var userinfostruct []Userinfo
|
var userinfostruct []Userinfo
|
||||||
for i := 0; i < len(usersarr); i++ {
|
for i := 0; i < len(usersarr); i++ {
|
||||||
uname := string(usersarr[i])
|
uname := string(usersarr[i])
|
||||||
userinfostruct = append(userinfostruct, userdata(uname, usersonlinededup))
|
userinfostruct = append(userinfostruct, userdata(uname, strings.TrimSuffix(usersonlinededup, "\n")))
|
||||||
}
|
}
|
||||||
log.Info(userinfostruct)
|
|
||||||
data := Userstruct{
|
data := Userstruct{
|
||||||
Status: c.Response().StatusCode(),
|
Status: c.Response().StatusCode(),
|
||||||
Online: output,
|
Online: output,
|
||||||
|
Loading…
Reference in New Issue
Block a user