1
0

link.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package conn
  2. import "time"
  3. type Secret struct {
  4. Password string
  5. Conn *Conn
  6. }
  7. func NewSecret(p string, conn *Conn) *Secret {
  8. return &Secret{
  9. Password: p,
  10. Conn: conn,
  11. }
  12. }
  13. type Link struct {
  14. ConnType string //连接类型
  15. Host string //目标
  16. Crypt bool //加密
  17. Compress bool
  18. LocalProxy bool
  19. RemoteAddr string
  20. Option Options
  21. }
  22. type Option func(*Options)
  23. type Options struct {
  24. Timeout time.Duration
  25. }
  26. var defaultTimeOut = time.Second * 5
  27. func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, opts ...Option) *Link {
  28. options := newOptions(opts...)
  29. return &Link{
  30. RemoteAddr: remoteAddr,
  31. ConnType: connType,
  32. Host: host,
  33. Crypt: crypt,
  34. Compress: compress,
  35. LocalProxy: localProxy,
  36. Option: options,
  37. }
  38. }
  39. func newOptions(opts ...Option) Options {
  40. opt := Options{
  41. Timeout: defaultTimeOut,
  42. }
  43. for _, o := range opts {
  44. o(&opt)
  45. }
  46. return opt
  47. }
  48. func LinkTimeout(t time.Duration) Option {
  49. return func(opt *Options) {
  50. opt.Timeout = t
  51. }
  52. }