-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfastagi.go
64 lines (52 loc) · 1.21 KB
/
fastagi.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
64
package main
import (
"fmt"
"log"
"net"
"os"
"github.com/staskobzar/goagi"
)
func serve(conn net.Conn) {
defer conn.Close()
dbg := log.New(os.Stdout, "fastagi example: ", log.Lmicroseconds)
agi, err := goagi.New(conn, conn, dbg)
if err != nil {
panic(err)
}
resp, err := agi.Verbose("Hello World!")
if err != nil {
dbg.Printf("Failed verbose command: %s", err)
return
}
dbg.Printf("Verbose response code: %d", resp.Code())
resp, _ = agi.GetVariable("CHANNEL")
dbg.Printf("Asterisk channel variable: %s", resp.Value())
resp, err = agi.GetData("welcome", 0, 2)
if err != nil {
panic(err)
}
dbg.Printf("Get Data response code: %d", resp.Code())
dbg.Printf("Get Data response result: %d", resp.Result())
dbg.Printf("Get Data response value: %s", resp.Value())
dbg.Printf("Get Data response data: %s", resp.Data())
resp, err = agi.GetVariable("CDR(duration)")
if err != nil {
panic(err)
}
dbg.Printf("CDR duration value: %s", resp.Value())
agi.Verbose("Goodbye!")
}
func main() {
fmt.Println("[x] Starting FastAGI script")
ln, err := net.Listen("tcp", "127.0.0.1:4575")
if err != nil {
panic(err)
}
for {
conn, err := ln.Accept()
if err != nil {
panic(err)
}
go serve(conn)
}
}