forked from StatCan/go-birdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobirdc.go
55 lines (48 loc) · 1.37 KB
/
gobirdc.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 gobirdc
import (
"github.com/StatCan/go-birdc/socket"
)
// A client wrapper for gobirdc which provides access to a number of
// thethe functions/methods available in the birdc binary
type BirdClient struct {
s *socket.BirdSocket
}
// BirdClientOptions describe configuration parameters used in the BirdClient
// `Path“ is the path to the BIRD unix domain socket
// `SocketBufferSize` is the size (in bytes) of the read buffer for reading from the BIRD daemon.
type BirdClientOptions struct {
Path string
SocketBufferSize int
}
// New creates a new BirdClient.
//
// This function takes an optional BirdClientOptions struct which can be used to
// override the default socket path and socket buffer size.
//
// If no options are provided, the default socket path and buffer size will be used.
//
// Example:
//
// client := gobirdc.New()
// client := gobirdc.New(&gobirdc.BirdClientOptions{
// Path: "/run/bird/bird.ctl",
// SocketBufferSize: 4096,
// }
func New(opts *BirdClientOptions) *BirdClient {
path := "/run/bird/bird.ctl"
socket_buffer_size := 4096
if opts == nil {
return &BirdClient{
s: socket.NewBirdSocket(path, socket_buffer_size),
}
}
if opts.Path != "" {
path = opts.Path
}
if opts.SocketBufferSize != 0 {
socket_buffer_size = opts.SocketBufferSize
}
return &BirdClient{
s: socket.NewBirdSocket(path, socket_buffer_size),
}
}