-
Notifications
You must be signed in to change notification settings - Fork 10
/
options.go
45 lines (32 loc) · 911 Bytes
/
options.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
package xco
import (
"log"
"context"
)
// Options define the series of options required to build a component
type Options struct {
// Name defines the component name
Name string
// SharedSecret is the secret shared between the server and component
SharedSecret string
// Address is the address of the XMPP server
Address string
// The (optional) parent context
Context context.Context
// Logger is an optional logger to which to send raw XML stanzas
// sent and received. It's primarily intended for debugging and
// development.
Logger *log.Logger
}
// NewComponent creates a new component from the given options
func NewComponent(opts Options) (*Component, error) {
if opts.Context == nil {
opts.Context = context.Background()
}
var c Component
c.ctx, c.cancelFn = context.WithCancel(opts.Context)
if err := c.init(opts); err != nil {
return nil, err
}
return &c, nil
}