Skip to content

Commit

Permalink
race fix and some remarks in readmy added
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Ivakha committed Feb 26, 2017
1 parent f0f60ef commit 61bc140
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ API has been changed in v0.1.2. Please read the godoc.

Usage is pretty simple.

To install:
## Installation:

`go get github.com/ivahaev/amigo`

Then import module to your project:
## Using
Import module to your project:
```go
import "github.com/ivahaev/amigo"
```
Expand Down Expand Up @@ -70,3 +71,7 @@ func main() {
}
}
```

## SIC!
You should not modify received events, because it can be read in another amigo goroutine.
If you need to modify, you should copy all values to another map and modify it.
3 changes: 2 additions & 1 deletion ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ func (a *amiAdapter) actionWriter(stop chan struct{}) {
}

func (a *amiAdapter) distribute(event map[string]string) {
actionID := event["ActionID"]
a.EventsChan <- event

if actionID := event["ActionID"]; actionID != "" {
if actionID != "" {
a.mutex.RLock()
resChan := a.responseChans[actionID]
a.mutex.RUnlock()
Expand Down
12 changes: 8 additions & 4 deletions amigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var (
version = "0.1.4"
version = "0.1.5"

// TODO: implement function to clear old data in handlers.
agiCommandsHandlers = make(map[string]agiCommand)
Expand Down Expand Up @@ -161,16 +161,20 @@ func (a *Amigo) Connect() {
go func() {
for {
var e = <-a.ami.EventsChan

a.handlerMutex.RLock()

var event = strings.ToUpper(e["Event"])
if len(e["Time"]) == 0 {
e["Time"] = time.Now().Format(time.RFC3339Nano)
}

if a.defaultChannel != nil {
go func(e map[string]string) {
a.defaultChannel <- e
}(e)
}
var event = strings.ToUpper(e["Event"])
if event != "" && (a.handlers[event] != nil || a.defaultHandler != nil) {

if len(event) != 0 && (a.handlers[event] != nil || a.defaultHandler != nil) {
if a.capitalizeProps {
ev := map[string]string{}
for k, v := range e {
Expand Down

0 comments on commit 61bc140

Please sign in to comment.