/
qman.go
63 lines (53 loc) · 1.42 KB
/
qman.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
56
57
58
59
60
61
62
63
package main
import (
"http"
"json"
"os"
"io/ioutil"
"flag"
"fmt"
)
type Queue struct { QueueId string }
var (
sickleUrl = "http://sickle:jHTbTrJtBry8WZIl@localhost:9292"
addr = flag.String("addr", ":1718", "http service address")
)
func sickle_lookup(u ,p ,q_name string, q *Queue) {
url := sickleUrl + "/lookup?username=" + u + "&password=" + p + "&queue_name=" + q_name
client := new(http.Client)
resp, _, _ := client.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode == 404 {
fmt.Println("could not find queue")
}
json.Unmarshal(body,q)
return
}
func write_enqueue_stats(q *Queue, payload []byte) os.Error {
fmt.Println("writing stats")
return ioutil.WriteFile("stats.txt", payload , 0600)
}
func write_enqueue_payload(q *Queue, payload []byte) os.Error {
fmt.Println("writing to queue")
filename := q.QueueId+".txt"
return ioutil.WriteFile(filename, payload, 0600)
}
func (q *Queue) enqueue(payload []byte) {
sickle_lookup("user","pass","default_queue",q)
go write_enqueue_payload(q, payload)
go write_enqueue_stats(q, payload)
fmt.Println("200")
return
}
func echo(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "success")
}
func main() {
flag.Parse()
http.HandleFunc("/enqueue", echo)
fmt.Println("listening on", *addr)
http.ListenAndServe(*addr, nil)
//payload := []byte("Class.method")
//queue := new(Queue)
//queue.enqueue(payload)
}