options_reader.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) 2013 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution, and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Seth Hoenig
  11. * Allan Stockdill-Mander
  12. * Mike Robertson
  13. */
  14. package mqtt
  15. import (
  16. "crypto/tls"
  17. "net/http"
  18. "net/url"
  19. "time"
  20. )
  21. // ClientOptionsReader provides an interface for reading ClientOptions after the client has been initialized.
  22. type ClientOptionsReader struct {
  23. options *ClientOptions
  24. }
  25. //Servers returns a slice of the servers defined in the clientoptions
  26. func (r *ClientOptionsReader) Servers() []*url.URL {
  27. s := make([]*url.URL, len(r.options.Servers))
  28. for i, u := range r.options.Servers {
  29. nu := *u
  30. s[i] = &nu
  31. }
  32. return s
  33. }
  34. //ResumeSubs returns true if resuming stored (un)sub is enabled
  35. func (r *ClientOptionsReader) ResumeSubs() bool {
  36. s := r.options.ResumeSubs
  37. return s
  38. }
  39. //ClientID returns the set client id
  40. func (r *ClientOptionsReader) ClientID() string {
  41. s := r.options.ClientID
  42. return s
  43. }
  44. //Username returns the set username
  45. func (r *ClientOptionsReader) Username() string {
  46. s := r.options.Username
  47. return s
  48. }
  49. //Password returns the set password
  50. func (r *ClientOptionsReader) Password() string {
  51. s := r.options.Password
  52. return s
  53. }
  54. //CleanSession returns whether Cleansession is set
  55. func (r *ClientOptionsReader) CleanSession() bool {
  56. s := r.options.CleanSession
  57. return s
  58. }
  59. func (r *ClientOptionsReader) Order() bool {
  60. s := r.options.Order
  61. return s
  62. }
  63. func (r *ClientOptionsReader) WillEnabled() bool {
  64. s := r.options.WillEnabled
  65. return s
  66. }
  67. func (r *ClientOptionsReader) WillTopic() string {
  68. s := r.options.WillTopic
  69. return s
  70. }
  71. func (r *ClientOptionsReader) WillPayload() []byte {
  72. s := r.options.WillPayload
  73. return s
  74. }
  75. func (r *ClientOptionsReader) WillQos() byte {
  76. s := r.options.WillQos
  77. return s
  78. }
  79. func (r *ClientOptionsReader) WillRetained() bool {
  80. s := r.options.WillRetained
  81. return s
  82. }
  83. func (r *ClientOptionsReader) ProtocolVersion() uint {
  84. s := r.options.ProtocolVersion
  85. return s
  86. }
  87. func (r *ClientOptionsReader) TLSConfig() *tls.Config {
  88. s := r.options.TLSConfig
  89. return s
  90. }
  91. func (r *ClientOptionsReader) KeepAlive() time.Duration {
  92. s := time.Duration(r.options.KeepAlive * int64(time.Second))
  93. return s
  94. }
  95. func (r *ClientOptionsReader) PingTimeout() time.Duration {
  96. s := r.options.PingTimeout
  97. return s
  98. }
  99. func (r *ClientOptionsReader) ConnectTimeout() time.Duration {
  100. s := r.options.ConnectTimeout
  101. return s
  102. }
  103. func (r *ClientOptionsReader) MaxReconnectInterval() time.Duration {
  104. s := r.options.MaxReconnectInterval
  105. return s
  106. }
  107. func (r *ClientOptionsReader) AutoReconnect() bool {
  108. s := r.options.AutoReconnect
  109. return s
  110. }
  111. func (r *ClientOptionsReader) WriteTimeout() time.Duration {
  112. s := r.options.WriteTimeout
  113. return s
  114. }
  115. func (r *ClientOptionsReader) MessageChannelDepth() uint {
  116. s := r.options.MessageChannelDepth
  117. return s
  118. }
  119. func (r *ClientOptionsReader) HTTPHeaders() http.Header {
  120. h := r.options.HTTPHeaders
  121. return h
  122. }