Test Failed
Push — master ( 569253...ad9af8 )
by Vyacheslav
01:38
created

examples/fastagi.go   A

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 42
dl 0
loc 62
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B main.Serve 0 37 5
1
package main
2
3
import (
4
	"fmt"
5
	"log"
6
	"net"
7
	"os"
8
9
	"github.com/staskobzar/goagi"
10
)
11
12
func Serve(conn net.Conn) {
0 ignored issues
show
introduced by
exported function Serve should have comment or be unexported
Loading history...
13
	defer conn.Close()
14
15
	dbg := log.New(os.Stdout, "fastagi example: ", log.Lmicroseconds)
16
	agi, err := goagi.New(conn, conn, dbg)
17
	if err != nil {
18
		panic(err)
19
	}
20
21
	resp, err := agi.Verbose("Hello World!")
22
	if err != nil {
23
		dbg.Printf("Failed verbose command: %s", err)
24
		return
25
	}
26
	dbg.Printf("Verbose response code: %d", resp.Code())
27
28
	resp, _ = agi.GetVariable("CHANNEL")
29
	dbg.Printf("Asterisk channel variable: %s", resp.Value())
30
31
	resp, err = agi.GetData("welcome", 0, 2)
32
	if err != nil {
33
		panic(err)
34
	}
35
36
	dbg.Printf("Get Data response code: %d", resp.Code())
37
	dbg.Printf("Get Data response result: %d", resp.Result())
38
	dbg.Printf("Get Data response value: %s", resp.Value())
39
	dbg.Printf("Get Data response data: %s", resp.Data())
40
41
	resp, err = agi.GetVariable("CDR(duration)")
42
	if err != nil {
43
		panic(err)
44
	}
45
46
	dbg.Printf("CDR duration value: %s", resp.Value())
47
48
	agi.Verbose("Goodbye!")
49
}
50
51
func main() {
52
	fmt.Println("[x] Starting FastAGI script")
53
	ln, err := net.Listen("tcp", "127.0.0.1:4575")
54
	if err != nil {
55
		panic(err)
56
	}
57
	for {
58
		conn, err := ln.Accept()
59
		if err != nil {
60
			panic(err)
61
		}
62
		go Serve(conn)
63
	}
64
}
65