-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsl.go
61 lines (51 loc) · 1.32 KB
/
tsl.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
package tsl
import (
"github.com/jasday/go-tsl-v5/pkg/client"
"github.com/jasday/go-tsl-v5/pkg/server"
)
func NewServer(addr string, options ...server.Option) (*server.Server, error) {
// Default values
if addr == "localhost" {
addr = "127.0.0.1"
}
svr := &server.Server{
Address: addr,
Port: 5900,
Protocol: server.UDP,
EnforcePacketLength: false,
EnforcedVersionNumber: 0,
}
// Apply options
for _, op := range options {
err := op(svr)
if err != nil {
return nil, err
}
}
return svr, nil
}
func OptionUsePort(p int) server.Option {
return func(s *server.Server) error { s.Port = p; return nil }
}
func OptionUseTCP() server.Option {
return func(s *server.Server) error { s.Protocol = server.TCP; return nil }
}
func OptionEnforcePacketLengthCheck() server.Option {
return func(s *server.Server) error { s.EnforcePacketLength = true; return nil }
}
func OptionEnforceTslVersion(version int) server.Option {
return func(s *server.Server) error { s.EnforcedVersionNumber = version; return nil }
}
func NewClient(addr string, options ...client.Option) (*client.Client, error) {
client := &client.Client{
Protocol: server.UDP,
}
// Apply options
for _, op := range options {
err := op(client)
if err != nil {
return nil, err
}
}
return client, nil
}