/
pattern-matcher.go
55 lines (42 loc) · 996 Bytes
/
pattern-matcher.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"github.com/garyburd/redigo/redis"
"fmt"
"github.com/hoisie/web"
"encoding/json"
"strconv"
)
var conn redis.Conn
var err error
func getFactsFromRedis(order_id int64) []map[string]interface{} {
facts_json, err := redis.String(conn.Do("GET", order_id))
if err != nil {
// handle error
}
fmt.Println(facts_json)
var facts []map[string]interface{}
err = json.Unmarshal([]byte(facts_json), &facts)
fmt.Println(facts)
return facts
}
func handleFilter(ctx *web.Context, val string) {
order_id, err := strconv.ParseInt(ctx.Params["id"], 10, 64)
if err != nil {
// handle error
}
facts := getFactsFromRedis(order_id)
response, err := json.Marshal(facts)
if err != nil {
// handle error
}
ctx.WriteString(string(response[:]))
}
func main() {
conn, err = redis.Dial("tcp", ":6379")
if err != nil {
// handle error
}
defer conn.Close()
web.Post("(.*)", handleFilter)
web.Run("0.0.0.0:9999")
}