-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
72 lines (66 loc) · 1.41 KB
/
option.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
62
63
64
65
66
67
68
69
70
71
72
package server
import (
"crypto/tls"
"net"
)
// UNIXSOPtions contains necessary information required by unix socket server.
type UNIXSOptions struct {
// TODO
}
// TCPOptions contains necessarry information required by TCP server.
type TCPOptions struct {
// TODO
}
// TLSOptions contains neccessary information required by TLS server.
type TLSOptions struct {
Curves []tls.CurveID
Ciphers []uint16
Cert string
Key string
Ca string
HandshakeTimeout int
ShouldVerify bool
}
// ServerConfigs is a struct for configuring the server.
type ServerConfigs struct {
Config interface{}
Addr string
Mode byte
Type byte
// TRate is the cycle interval in milliseconds
// for performing status check.
TRate int
// TODO
// . add callbacks
}
func precheckOpts(opts *ServerConfigs) error {
// TODO
// . precheck server options before proceeding
_, _, err := net.SplitHostPort(opts.Addr)
if err != nil {
return SRVInvalidAddr
}
if opts.Config != nil {
switch opts.Mode {
case ProtoTCP:
if _, ok := opts.Config.(TCPOptions); !ok {
return SRVMissingOptions
}
return nil
case ProtoTLS:
if _, ok := opts.Config.(TLSOptions); !ok {
return SRVMissingOptions
}
return nil
case ProtoSSL:
// TODO
return SRVInvalidMode
case ProtoUNIXSO:
// TODO
return SRVInvalidMode
default:
return SRVInvalidMode
}
}
return nil
}