Files

64 lines
1.0 KiB
Go
Raw Permalink Normal View History

2019-02-09 17:07:47 +08:00
package conn
2019-12-01 23:18:11 +08:00
import "time"
2019-02-23 23:29:48 +08:00
type Secret struct {
Password string
Conn *Conn
}
func NewSecret(p string, conn *Conn) *Secret {
return &Secret{
Password: p,
Conn: conn,
}
}
2019-02-09 17:07:47 +08:00
type Link struct {
ConnType string //连接类型
Host string //目标
Crypt bool //加密
Compress bool
2019-04-08 17:01:08 +08:00
LocalProxy bool
RemoteAddr string
2019-12-01 23:18:11 +08:00
Option Options
2019-02-09 17:07:47 +08:00
}
2019-12-01 23:18:11 +08:00
type Option func(*Options)
type Options struct {
Timeout time.Duration
}
var defaultTimeOut = time.Second * 5
func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, opts ...Option) *Link {
options := newOptions(opts...)
2019-02-09 17:07:47 +08:00
return &Link{
RemoteAddr: remoteAddr,
ConnType: connType,
Host: host,
Crypt: crypt,
Compress: compress,
2019-04-08 17:01:08 +08:00
LocalProxy: localProxy,
2019-12-01 23:18:11 +08:00
Option: options,
}
}
func newOptions(opts ...Option) Options {
opt := Options{
Timeout: defaultTimeOut,
}
for _, o := range opts {
o(&opt)
}
return opt
}
func LinkTimeout(t time.Duration) Option {
return func(opt *Options) {
opt.Timeout = t
2019-02-09 17:07:47 +08:00
}
}