client_instance.go 362 B

1234567891011121314151617181920212223242526
  1. package mqtt_client
  2. var clientInstance *Client
  3. func InitInstance(opts *ClientOptions) {
  4. if clientInstance == nil {
  5. client, err := New(opts)
  6. if err != nil {
  7. panic(err)
  8. }
  9. clientInstance = client
  10. }
  11. }
  12. func DestroyInstance() {
  13. if clientInstance == nil {
  14. return
  15. }
  16. Destroy(clientInstance)
  17. }
  18. func GetInstance() *Client {
  19. return clientInstance
  20. }