-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
56 lines (45 loc) · 1.3 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2023 Wayback Archiver. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package proxier // import "github.com/wabarc/proxier"
import (
utls "github.com/refraction-networking/utls"
)
// UTLS represents a uTLS struct.
type UTLS struct {
proxy interface{}
clientHello *utls.ClientHelloID
config *utls.Config
}
// UTLSOption is a function type that modifies a UTLS struct by setting one of its fields.
type UTLSOption func(*UTLS)
// Options takes one or more UTLSOptions and returns a UTLS struct has been configured
// according to those options.
func UTLSOptions(options ...UTLSOption) UTLS {
var u UTLS
for _, o := range options {
o(&u)
}
if u.clientHello == nil {
u.clientHello = defaultClientHelloID
}
return u
}
// Proxy sets the proxy field of a UTLS struct to the given proxy.
func Proxy(p interface{}) UTLSOption {
return func(o *UTLS) {
o.proxy = p
}
}
// ClientHello sets the clientHello field of a UTLS struct to the given clientHello.
func ClientHello(ch *utls.ClientHelloID) UTLSOption {
return func(o *UTLS) {
o.clientHello = ch
}
}
// Config sets the utls config field of a UTLS struct to the given config.
func Config(c *utls.Config) UTLSOption {
return func(o *UTLS) {
o.config = c
}
}