mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
new: added new Meta field to Endpoint objects (closes #66)
This commit is contained in:
parent
f243262200
commit
02d414107e
3 changed files with 48 additions and 3 deletions
44
network/meta.go
Normal file
44
network/meta.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
sync.Mutex
|
||||
m map[string]interface{}
|
||||
}
|
||||
|
||||
// we want to protect concurrent access to the Meta
|
||||
// object so the m field needs to be unexported, this
|
||||
// is to have it in JSON regardless.
|
||||
type metaJSON struct {
|
||||
Values map[string]interface{} `json:"values"`
|
||||
}
|
||||
|
||||
func NewMeta() *Meta {
|
||||
return &Meta{
|
||||
m: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Meta) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(metaJSON{Values: m.m})
|
||||
}
|
||||
|
||||
func (m *Meta) Set(name string, value interface{}) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
m.m[name] = value
|
||||
}
|
||||
|
||||
func (m *Meta) Get(name string) interface{} {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
if v, found := m.m[name]; found == true {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue