-
Notifications
You must be signed in to change notification settings - Fork 3
/
constructor.go
55 lines (40 loc) · 845 Bytes
/
constructor.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 gopinba
import (
"fmt"
"net"
"os"
)
// New Pinba access object
//
// Example
//
// pinba := gopinba.New(&gopinba.Options{PinbaHost: "127.0.0.1", PinbaPort: 30002})
//
func New(options *Options) *Pinba {
hostname := "unknown"
serverName := "unknown"
pinbaHost := "127.0.0.1"
pinbaPort := 30002
if value, err := os.Hostname(); err == nil {
hostname = value
}
if options.ServerName != "" {
serverName = options.ServerName
}
if options.PinbaHost != "" {
pinbaHost = options.PinbaHost
}
if options.PinbaPort != 0 {
pinbaPort = options.PinbaPort
}
pinba := &Pinba{
hostname: hostname,
serverName: serverName,
connected: false,
}
if connect, err := net.Dial("udp", fmt.Sprintf("%s:%d", pinbaHost, pinbaPort)); err == nil {
pinba.connect = connect
pinba.connected = true
}
return pinba
}