-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package wigo | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/orcaman/concurrent-map" | ||
) | ||
|
||
type concurrentMapWigos struct { | ||
cmap.ConcurrentMap | ||
} | ||
|
||
|
||
func NewConcurrentMapWigos() *concurrentMapWigos { | ||
return &concurrentMapWigos{ | ||
ConcurrentMap: cmap.New(), | ||
} | ||
} | ||
|
||
func (m *concurrentMapWigos) UnmarshalJSON(b []byte) (err error) { | ||
// Reverse process of Marshal. | ||
|
||
tmp := make(map[string]*Wigo) | ||
|
||
// Unmarshal into a single map. | ||
if err := json.Unmarshal(b, &tmp); err != nil { | ||
return nil | ||
} | ||
|
||
_m := NewConcurrentMapWigos() | ||
// foreach key,value pair in temporary map insert into our concurrent map. | ||
for key, val := range tmp { | ||
_m.Set(key, val) | ||
} | ||
*m = *_m | ||
return nil | ||
} | ||
|
||
type concurrentMapProbes struct { | ||
cmap.ConcurrentMap | ||
} | ||
|
||
func NewConcurrentMapProbes() *concurrentMapProbes { | ||
return &concurrentMapProbes{ | ||
ConcurrentMap: cmap.New(), | ||
} | ||
} | ||
|
||
|
||
func (m *concurrentMapProbes) UnmarshalJSON(b []byte) (err error) { | ||
// Reverse process of Marshal. | ||
|
||
tmp := make(map[string]*ProbeResult) | ||
|
||
// Unmarshal into a single map. | ||
if err := json.Unmarshal(b, &tmp); err != nil { | ||
return nil | ||
} | ||
|
||
_m := NewConcurrentMapProbes() | ||
// foreach key,value pair in temporary map insert into our concurrent map. | ||
for key, val := range tmp { | ||
_m.Set(key, val) | ||
} | ||
*m = *_m | ||
return nil | ||
} |