mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
42b08db0b0
commit
7c2dc38819
4 changed files with 43 additions and 31 deletions
|
@ -2,7 +2,12 @@ package network
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
|
@ -43,6 +48,29 @@ func (m *Meta) Get(name string) interface{} {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (m *Meta) GetIntsWith(name string, with int, sorted bool) []int {
|
||||
sints := strings.Split(m.Get(name).(string), ",")
|
||||
ints := []int{with}
|
||||
|
||||
for _, s := range sints {
|
||||
n, err := strconv.Atoi(s)
|
||||
if err == nil {
|
||||
ints = append(ints, n)
|
||||
}
|
||||
}
|
||||
|
||||
return core.UniqueInts(ints, sorted)
|
||||
}
|
||||
|
||||
func (m *Meta) SetInts(name string, ints []int) {
|
||||
list := make([]string, len(ints))
|
||||
for i, n := range ints {
|
||||
list[i] = fmt.Sprintf("%d", n)
|
||||
}
|
||||
|
||||
m.Set(name, strings.Join(list, ","))
|
||||
}
|
||||
|
||||
func (m *Meta) GetOr(name string, dflt interface{}) interface{} {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue