pubnub

package module
v4.0.0-beta.3+incompat... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2017 License: MIT Imports: 18 Imported by: 0

README

#PubNub 3.14.0 client for Go

  • Go (1.2, 1.3, 1.4, 1.5, 1.6, 1.7.3, 1.8)
  • Google App Engine (1.9.28 - 2015-10-29)
  • Managed VMs (Google Cloud SDK 133.0.0)

Build Status codecov.io Go Report Card

Contact support@pubnub.com for all questions

##PubNub 3.14.0 Go based APIs Learn more at http://www.pubnub.com

Available in this repository

For Google App Engine

For Non Google App Engine

Contact support@pubnub.com for all questions

Documentation

Index

Constants

View Source
const (
	Version     = "4.0.0-beta.3"
	MaxSequence = 65535
)

Default constants

View Source
const (
	StrMissingPubKey       = "Missing Publish Key"
	StrMissingSubKey       = "Missing Subscribe Key"
	StrMissingChannel      = "Missing Channel"
	StrMissingChannelGroup = "Missing Channel Group"
	StrMissingMessage      = "Missing Message"
	StrMissingSecretKey    = "Missing Secret Key"
	StrMissingUuid         = "Missing Uuid"
)
View Source
const (
	RECONNECTION_INTERVAL              = 3
	RECONNECTION_MINEXPONENTIALBACKOFF = 1
	RECONNECTION_MAXEXPONENTIALBACKOFF = 32
)
View Source
const ADD_CHANNEL_CHANNEL_GROUP_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
View Source
const ALL_CHANNEL_GROUP = "/v1/channel-registration/sub-key/%s/channel-group/%s"
View Source
const DELETE_CHANNEL_GROUP = "/v1/channel-registration/sub-key/%s/channel-group/%s/remove"
View Source
const GET_STATE_PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s"
View Source
const GRANT_PATH = "/v1/auth/grant/sub-key/%s"
View Source
const HEARTBEAT_PATH = "/v2/presence/sub-key/%s/channel/%s/heartbeat"
View Source
const HISTORY_DELETE_PATH = "/v3/history/sub-key/%s/channel/%s"
View Source
const HISTORY_PATH = "/v2/history/sub-key/%s/channel/%s"
View Source
const LEAVE_PATH = "/v2/presence/sub-key/%s/channel/%s/leave"
View Source
const MAX_COUNT = 100
View Source
const (
	PRESENCE_TIMEOUT = 300
)
View Source
const PUBLISH_GET_PATH = "/publish/%s/%s/0/%s/%s/%s"
View Source
const PUBLISH_POST_PATH = "/publish/%s/%s/0/%s/%s"
View Source
const REMOVE_CHANNEL_CHANNEL_GROUP = "/v1/channel-registration/sub-key/%s/channel-group/%s"
View Source
const SET_STATE_PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s/data"
View Source
const SUBSCRIBE_PATH = "/v2/subscribe/%s/%s/0"
View Source
const TIME_PATH = "/time/0"

Variables

View Source
var GLOBAL_HERE_NOW_PATH = "/v2/presence/sub_key/%s"
View Source
var HERE_NOW_PATH = "/v2/presence/sub_key/%s/channel/%s"
View Source
var WHERE_NOW_PATH = "/v2/presence/sub-key/%s/uuid/%s"

Functions

func NewHttpClient

func NewHttpClient(connectTimeout int, responseReadTimeout int) *http.Client

Types

type AddChannelToChannelGroupBuilder

type AddChannelToChannelGroupBuilder struct {
	// contains filtered or unexported fields
}

func (*AddChannelToChannelGroupBuilder) Channels

func (*AddChannelToChannelGroupBuilder) Execute

func (*AddChannelToChannelGroupBuilder) Group

func (*AddChannelToChannelGroupBuilder) Transport

type AddChannelToChannelGroupResponse

type AddChannelToChannelGroupResponse struct {
}

type AllChannelGroupResponse

type AllChannelGroupResponse struct {
	Channels []string
	Group    string
}

type Config

type Config struct {
	PublishKey   string
	SubscribeKey string
	SecretKey    string
	AuthKey      string
	Origin       string
	Uuid         string
	CipherKey    string
	Secure       bool

	// net.Dialer.Timeout
	ConnectTimeout int

	// http.Client.Timeout for non-subscribe requests
	NonSubscribeRequestTimeout int

	// http.Client.Timeout for subscribe requests only
	SubscribeRequestTimeout int

	HeartbeatInterval int

	PresenceTimeout int

	MaximumReconnectionRetries int

	FilterExpression string

	PNReconnectionPolicy ReconnectionPolicy
}

func NewConfig

func NewConfig() *Config

func NewDemoConfig

func NewDemoConfig() *Config

func (*Config) SetPresenceTimeout

func (c *Config) SetPresenceTimeout(timeout int) *Config

func (*Config) SetPresenceTimeoutWithCustomInterval

func (c *Config) SetPresenceTimeoutWithCustomInterval(
	timeout, interval int) *Config

type Context

type Context interface {
	Deadline() (deadline time.Time, ok bool)
	Done() <-chan struct{}
	Err() error
	Value(key interface{}) interface{}
}

type DeleteChannelGroupResponse

type DeleteChannelGroupResponse struct{}

type GetStateResponse

type GetStateResponse struct {
	State map[string]interface{}
}

type GrantResponse

type GrantResponse struct {
	Level        string
	SubscribeKey string

	Ttl int

	Channels      map[string]*PNPAMEntityData
	ChannelGroups map[string]*PNPAMEntityData

	ReadEnabled   bool
	WriteEnabled  bool
	ManageEnabled bool
}

type HereNowChannelData

type HereNowChannelData struct {
	ChannelName string

	Occupancy int

	Occupants []HereNowOccupantsData
}

type HereNowOccupantsData

type HereNowOccupantsData struct {
	Uuid string

	State map[string]interface{}
}

type HereNowResponse

type HereNowResponse struct {
	TotalChannels  int
	TotalOccupancy int

	Channels []HereNowChannelData
}

type HistoryDeleteResponse

type HistoryDeleteResponse struct {
}

type HistoryResponse

type HistoryResponse struct {
	Messages       []HistoryResponseItem
	StartTimetoken int64
	EndTimetoken   int64
}

type HistoryResponseItem

type HistoryResponseItem struct {
	Message   interface{}
	Timetoken int64
}

type Listener

type Listener struct {
	Status   chan *PNStatus
	Message  chan *PNMessage
	Presence chan *PNPresence
}

func NewListener

func NewListener() *Listener

type ListenerManager

type ListenerManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type OperationType

type OperationType int
const (
	PNSubscribeOperation OperationType = 1 + iota
	PNUnsubscribeOperation
	PNPublishOperation
	PNHistoryOperation
	PNFetchMessagesOperation
	PNWhereNowOperation
	PNHereNowOperation
	PNHeartBeatOperation
	PNSetStateOperation
	PNGetStateOperation
	PNAddChannelsToChannelGroupOperation
	PNRemoveChannelFromChannelGroupOperation
	PNRemoveGroupOperation
	PNChannelsForGroupOperation
	PNPushNotificationsEnabledChannelsOperation
	PNAddPushNotificationsOnChannelsOperation
	PNRemovePushNotificationsFromChannelsOperation
	PNRemoveAllPushNotificationsOperation
	PNTimeOperation
	PNAccessManagerGrant
	PNAccessManagerRevoke
	PNDeleteMessagesOperation
)

func (OperationType) String

func (t OperationType) String() string

type PNAccessManagerKeyData

type PNAccessManagerKeyData struct {
	ReadEnabled   bool
	WriteEnabled  bool
	ManageEnabled bool
	Ttl           int
}

type PNMessage

type PNMessage struct {
	Message      interface{}
	UserMetadata interface{}

	SubscribedChannel string
	ActualChannel     string
	Channel           string
	Subscription      string
	Publisher         string
	Timetoken         int64
}

type PNPAMEntityData

type PNPAMEntityData struct {
	Name          string
	AuthKeys      map[string]*PNAccessManagerKeyData
	ReadEnabled   bool
	WriteEnabled  bool
	ManageEnabled bool
	Ttl           int
}

type PNPresence

type PNPresence struct {
	Event             string
	Uuid              string
	SubscribedChannel string
	ActualChannel     string
	Channel           string
	Subscription      string

	Occupancy int
	Timetoken int64
	Timestamp int64

	UserMetadata map[string]interface{}
	State        interface{}

	Join    []string
	Leave   []string
	Timeout []string
}

type PNStatus

type PNStatus struct {
	Category  StatusCategory
	Operation OperationType

	ErrorData  error
	Error      bool
	TlsEnabled bool
	StatusCode int
	Uuid       string
	AuthKey    string
	Origin     string
	// Should be same for non-google environment
	ClientRequest interface{}

	AffectedChannels      []string
	AffectedChannelGroups []string
}

type PubNub

type PubNub struct {
	sync.RWMutex

	Config *Config
	// contains filtered or unexported fields
}

No server connection will be established when you create a new PubNub object. To establish a new connection use Subscribe() function of PubNub type.

func NewPubNub

func NewPubNub(pnconf *Config) *PubNub

func NewPubNubDemo

func NewPubNubDemo() *PubNub

func (*PubNub) AddChannelToChannelGroup

func (pn *PubNub) AddChannelToChannelGroup() *AddChannelToChannelGroupBuilder

func (*PubNub) AddChannelToChannelGroupWithContext

func (pn *PubNub) AddChannelToChannelGroupWithContext(
	ctx Context) *AddChannelToChannelGroupBuilder

func (*PubNub) AddListener

func (pn *PubNub) AddListener(listener *Listener)

func (*PubNub) DeleteChannelGroup

func (pn *PubNub) DeleteChannelGroup() *deleteChannelGroupBuilder

func (*PubNub) DeleteChannelGroupWithContext

func (pn *PubNub) DeleteChannelGroupWithContext(
	ctx Context) *deleteChannelGroupBuilder

func (*PubNub) DeleteMessages

func (pn *PubNub) DeleteMessages() *historyDeleteBuilder

func (*PubNub) DeleteMessagesWithContext

func (pn *PubNub) DeleteMessagesWithContext() *historyDeleteBuilder

func (*PubNub) Destroy

func (pn *PubNub) Destroy()

func (*PubNub) GetClient

func (pn *PubNub) GetClient() *http.Client

Set a client for transactional requests

func (*PubNub) GetListeners

func (pn *PubNub) GetListeners() map[*Listener]bool

func (*PubNub) GetState

func (pn *PubNub) GetState() *getStateBuilder

func (*PubNub) GetStateWithContext

func (pn *PubNub) GetStateWithContext(ctx Context) *getStateBuilder

func (*PubNub) GetSubscribeClient

func (pn *PubNub) GetSubscribeClient() *http.Client

Set a client for transactional requests

func (*PubNub) GetSubscribedChannels

func (pn *PubNub) GetSubscribedChannels() []string

func (*PubNub) GetSubscribedGroups

func (pn *PubNub) GetSubscribedGroups() []string

func (*PubNub) Grant

func (pn *PubNub) Grant() *grantBuilder

func (*PubNub) GrantWithContext

func (pn *PubNub) GrantWithContext(ctx Context) *grantBuilder

func (*PubNub) HereNow

func (pn *PubNub) HereNow() *hereNowBuilder

func (*PubNub) HereNowWithContext

func (pn *PubNub) HereNowWithContext(ctx Context) *hereNowBuilder

func (*PubNub) History

func (pn *PubNub) History() *historyBuilder

func (*PubNub) HistoryWithContext

func (pn *PubNub) HistoryWithContext(ctx Context) *historyBuilder

func (*PubNub) Leave

func (pn *PubNub) Leave() *leaveBuilder

func (*PubNub) LeaveWithContext

func (pn *PubNub) LeaveWithContext(ctx Context) *leaveBuilder

func (*PubNub) ListChannelsInChannelGroup

func (pn *PubNub) ListChannelsInChannelGroup() *allChannelGroupBuilder

func (*PubNub) ListChannelsInChannelGroupWithContext

func (pn *PubNub) ListChannelsInChannelGroupWithContext(
	ctx Context) *allChannelGroupBuilder

func (*PubNub) Publish

func (pn *PubNub) Publish() *publishBuilder

func (*PubNub) PublishWithContext

func (pn *PubNub) PublishWithContext(ctx Context) *publishBuilder

func (*PubNub) RemoveChannelFromChannelGroup

func (pn *PubNub) RemoveChannelFromChannelGroup() *RemoveChannelFromChannelGroupBuilder

func (*PubNub) RemoveChannelFromChannelGroupWithContext

func (pn *PubNub) RemoveChannelFromChannelGroupWithContext(
	ctx Context) *RemoveChannelFromChannelGroupBuilder

func (*PubNub) RemoveListener

func (pn *PubNub) RemoveListener(listener *Listener)

func (*PubNub) SetClient

func (pn *PubNub) SetClient(c *http.Client)

Set a client for transactional requests

func (*PubNub) SetState

func (pn *PubNub) SetState() *setStateBuilder

func (*PubNub) SetStateWithContext

func (pn *PubNub) SetStateWithContext(ctx Context) *setStateBuilder

func (*PubNub) SetSubscribeClient

func (pn *PubNub) SetSubscribeClient(client *http.Client)

func (*PubNub) Subscribe

func (pn *PubNub) Subscribe(operation *SubscribeOperation)

func (*PubNub) Time

func (pn *PubNub) Time() *timeBuilder

func (*PubNub) TimeWithContext

func (pn *PubNub) TimeWithContext(ctx Context) *timeBuilder

func (*PubNub) Unsubscribe

func (pn *PubNub) Unsubscribe(operation *UnsubscribeOperation)

func (*PubNub) UnsubscribeAll

func (pn *PubNub) UnsubscribeAll()

func (*PubNub) WhereNow

func (pn *PubNub) WhereNow() *whereNowBuilder

func (*PubNub) WhereNowWithContext

func (pn *PubNub) WhereNowWithContext(ctx Context) *whereNowBuilder

type PublishResponse

type PublishResponse struct {
	Timestamp int
}

type ReconnectionManager

type ReconnectionManager struct {
	sync.RWMutex

	ExponentialMultiplier int
	FailedCalls           int
	Milliseconds          int

	OnReconnection              func()
	OnMaxReconnectionExhaustion func()

	DoneTimer chan bool

	Timer *time.Ticker
	// contains filtered or unexported fields
}

func (*ReconnectionManager) HandleOnMaxReconnectionExhaustion

func (m *ReconnectionManager) HandleOnMaxReconnectionExhaustion(handler func())

func (*ReconnectionManager) HandleReconnection

func (m *ReconnectionManager) HandleReconnection(handler func())

type ReconnectionPolicy

type ReconnectionPolicy int
const (
	PNNonePolicy ReconnectionPolicy = 1 + iota
	PNLinearPolicy
	PNExponentialPolicy
)

TODO: add prefix

type RemoveChannelFromChannelGroupBuilder

type RemoveChannelFromChannelGroupBuilder struct {
	// contains filtered or unexported fields
}

func (*RemoveChannelFromChannelGroupBuilder) Channels

func (*RemoveChannelFromChannelGroupBuilder) Execute

func (*RemoveChannelFromChannelGroupBuilder) Group

type RemoveChannelFromChannelGroupResponse

type RemoveChannelFromChannelGroupResponse struct {
}

type ResponseInfo

type ResponseInfo struct {
	Operation OperationType

	StatusCode int

	TlsEnabled bool

	Origin  string
	Uuid    string
	AuthKey string

	OriginalResponse *http.Response
}

type SetStateResponse

type SetStateResponse struct {
	State []interface{}
}

type StateManager

type StateManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type StateOperation

type StateOperation struct {
	// contains filtered or unexported fields
}

type StatusCategory

type StatusCategory int
const (
	PNUnknownCategory StatusCategory = 1 + iota
	// Request timeout reached
	PNTimeoutCategory
	// Subscribe received an initial timetoken
	PNConnectedCategory
	// Disconnected due network error
	PNDisconnectedCategory
	// Context cancelled
	PNCancelledCategory
	PNLoopStopCategory
	PNAcknowledgmentCategory
	PNBadRequestCategory
	PNAccessDeniedCategory
	PNNoStubMatchedCategory
	PNReconnectedCategory
	PNReconnectionAttemptsExhausted
)

func (StatusCategory) String

func (c StatusCategory) String() string

type StatusResponse

type StatusResponse struct {
	Error error

	Category  StatusCategory
	Operation OperationType

	StatusCode int

	TlsEnabled bool

	Uuid             string
	AuthKey          string
	Origin           string
	OriginalResponse string

	AffectedChannels      []string
	AffectedChannelGroups []string
}

type SubscribeOperation

type SubscribeOperation struct {
	Channels         []string
	ChannelGroups    []string
	PresenceEnabled  bool
	Timetoken        int64
	FilterExpression string
	Transport        http.RoundTripper
}

type SubscribeOpts

type SubscribeOpts struct {
	Channels []string
	Groups   []string

	Heartbeat        int
	Region           string
	Timetoken        int64
	FilterExpression string
	WithPresence     bool

	Transport http.RoundTripper
	// contains filtered or unexported fields
}

type SubscribeResponse

type SubscribeResponse struct {
}

type SubscriptionItem

type SubscriptionItem struct {
	// contains filtered or unexported fields
}

type SubscriptionManager

type SubscriptionManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*SubscriptionManager) AddListener

func (m *SubscriptionManager) AddListener(listener *Listener)

func (*SubscriptionManager) Disconnect

func (m *SubscriptionManager) Disconnect()

func (*SubscriptionManager) GetListeners

func (m *SubscriptionManager) GetListeners() map[*Listener]bool

func (*SubscriptionManager) RemoveAllListeners

func (m *SubscriptionManager) RemoveAllListeners()

func (*SubscriptionManager) RemoveListener

func (m *SubscriptionManager) RemoveListener(listener *Listener)

type TimeResponse

type TimeResponse struct {
	Timetoken int64
}

type UnsubscribeOperation

type UnsubscribeOperation struct {
	Channels      []string
	ChannelGroups []string
}

type WhereNowResponse

type WhereNowResponse struct {
	Channels []string
}

Directories

Path Synopsis
examples
cli
tests
e2e

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL