nps/lib/conn/link.go

64 lines
1.0 KiB
Go
Raw Normal View History

2019-02-09 09:07:47 +00:00
package conn
import "time"
2019-02-23 15:29:48 +00:00
type Secret struct {
Password string
Conn *Conn
}
func NewSecret(p string, conn *Conn) *Secret {
return &Secret{
Password: p,
Conn: conn,
}
}
2019-02-09 09:07:47 +00:00
type Link struct {
ConnType string //连接类型
Host string //目标
Crypt bool //加密
Compress bool
2019-04-08 09:01:08 +00:00
LocalProxy bool
RemoteAddr string
Option Options
}
type Option func(*Options)
type Options struct {
Timeout time.Duration
2019-02-09 09:07:47 +00:00
}
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 09:07:47 +00:00
return &Link{
RemoteAddr: remoteAddr,
ConnType: connType,
Host: host,
Crypt: crypt,
Compress: compress,
2019-04-08 09:01:08 +00:00
LocalProxy: localProxy,
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-26 14:40:28 +00:00
}
}