Mutex was added
This commit is contained in:
@@ -4,13 +4,14 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync"
|
||||
"github.com/dedkovd/noolite"
|
||||
"net/http"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func sendCommand(command string, channel, value, r, g, b int) error {
|
||||
func sendCommand(mutex *sync.Mutex, command string, channel, value, r, g, b int) error {
|
||||
if channel == -1 {
|
||||
return errors.New("Channel was not set")
|
||||
}
|
||||
@@ -19,6 +20,8 @@ func sendCommand(command string, channel, value, r, g, b int) error {
|
||||
return errors.New("Command was not set")
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
n, err := noolite.DefaultNooliteAdapter()
|
||||
|
||||
if err != nil {
|
||||
@@ -94,8 +97,10 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
mutex := &sync.Mutex{}
|
||||
|
||||
if *http_port < 0 {
|
||||
err := sendCommand(*command, *channel, *value, *red, *green, *blue)
|
||||
err := sendCommand(mutex, *command, *channel, *value, *red, *green, *blue)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -104,7 +109,7 @@ func main() {
|
||||
http.HandleFunc("/noolite/", func(w http.ResponseWriter, r *http.Request) {
|
||||
command, channel, value, red, green, blue := parseParams(r.URL.Path[1:])
|
||||
|
||||
err := sendCommand(command, channel, value, red, green, blue)
|
||||
err := sendCommand(mutex, command, channel, value, red, green, blue)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "{\"error\": %q}", err)
|
||||
|
||||
Reference in New Issue
Block a user