-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathincomingTxWatcher.go
More file actions
40 lines (30 loc) · 864 Bytes
/
incomingTxWatcher.go
File metadata and controls
40 lines (30 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/garyburd/redigo/redis"
)
type commandStruct struct {
Command string
}
var conn redis.Conn
func handler(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
cmd := struct{ Command string }{""}
err := decoder.Decode(&cmd)
failOnError(err, "Decoding Failed")
//Validate Command
//Add it to Redis
_, err = conn.Do("RPUSH", pendingTxKey, cmd.Command)
failOnError(err, "Failed to push to worker queue")
responseText := fmt.Sprintf("Successfully performed %s\n", cmd.Command)
fmt.Fprintf(w, responseText, r.URL.Path[1:])
}
func incomingTxWatcher() {
conn = redisPool.Get()
port := fmt.Sprintf(":%d", config.Redis.Port+*workerNum)
consoleLog.Debugf("Started watching on port %s\n", port)
http.HandleFunc("/", handler)
http.ListenAndServe(port, nil)
}