Documentation ¶
Index ¶
- Constants
- func PathToRID(path, query, prefix string) string
- func PathToRIDAction(path, query, prefix string) (string, string)
- func RIDToPath(rid, prefix string) string
- func RegisterAPIEncoderFactory(name string, f APIEncoderFactory)
- type APIEncoder
- type APIEncoderFactory
- type Config
- type ConnSubscriber
- type Service
- func (s *Service) Debugf(format string, v ...interface{})
- func (s *Service) Errorf(format string, v ...interface{})
- func (s *Service) GetWSHandlerFunc() http.Handler
- func (s *Service) Logf(format string, v ...interface{})
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) SetLogger(l logger.Logger) *Service
- func (s *Service) Start() (err error)
- func (s *Service) Stop(err error)
- func (s *Service) StopChannel() <-chan error
- func (s *Service) Tracef(format string, v ...interface{})
- type Subscription
- func (s *Subscription) CID() string
- func (s *Subscription) CanCall(action string, cb func(err error))
- func (s *Subscription) CanGet(cb func(err error))
- func (s *Subscription) CollectionValues() []codec.Value
- func (s *Subscription) Dispose()
- func (s *Subscription) Error() error
- func (s *Subscription) Event(event *rescache.ResourceEvent)
- func (s *Subscription) GetRPCResources() *rpc.Resources
- func (s *Subscription) IsReady() bool
- func (s *Subscription) IsSent() bool
- func (s *Subscription) Loaded(resourceSub *rescache.ResourceSubscription, err error)
- func (s *Subscription) ModelValues() map[string]codec.Value
- func (s *Subscription) OnReady(cb func())
- func (s *Subscription) RID() string
- func (s *Subscription) Reaccess(t *rescache.Throttle)
- func (s *Subscription) Ref(rid string) *Subscription
- func (s *Subscription) ReleaseRPCResources()
- func (s *Subscription) ResourceName() string
- func (s *Subscription) ResourceQuery() string
- func (s *Subscription) ResourceType() rescache.ResourceType
- func (s *Subscription) Token() json.RawMessage
Constants ¶
const ( // Version is the current version for the server. Version = "1.7.5" // ProtocolVersion is the implemented RES protocol version. ProtocolVersion = "1.2.2" // DefaultAddr is the default host for client connections. DefaultAddr = "0.0.0.0" // DefaultPort is the default port for client connections. DefaultPort = 8080 // DefaultWSPath is the default path for WebSocket connections. DefaultWSPath = "/" // DefaultAPIPath is the default path to web resource. DefaultAPIPath = "/api" // DefaultAPIEncoding is the default encoding for web resources. DefaultAPIEncoding = "json" // WSTimeout is the wait time for WebSocket connections to close on shutdown. WSTimeout = 3 * time.Second // MQTimeout is the wait time for the messaging client to close on shutdown. MQTimeout = 3 * time.Second // WSConnWorkerQueueSize is the size of the queue for each connection worker. WSConnWorkerQueueSize = 256 // CIDPlaceholder is the placeholder tag for the connection ID. CIDPlaceholder = "{cid}" // SubscriptionCountLimit is the subscription limit of a single connection. SubscriptionCountLimit = 256 // CacheWorkers is the number of goroutines handling cached resources. CacheWorkers = 10 // UnsubscribeDelay is the delay for the cache to unsubscribe and evict resources no longer used. UnsubscribeDelay = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func PathToRID ¶ added in v1.2.1
PathToRID parses a raw URL path and returns the resource ID. The prefix is the beginning of the path which is not part of the resource ID, and it should both start and end with /. Eg. "/api/"
func PathToRIDAction ¶ added in v1.2.1
PathToRIDAction parses a raw URL path and returns the resource ID and action. The prefix is the beginning of the path which is not part of the resource ID, and it should both start and end with /. Eg. "/api/"
func RIDToPath ¶ added in v1.2.1
RIDToPath converts a resource ID to a URL path string. The prefix is the part of the path that should be prepended to the resource ID path, and it should both start and end with /. Eg. "/api/".
func RegisterAPIEncoderFactory ¶ added in v1.2.1
func RegisterAPIEncoderFactory(name string, f APIEncoderFactory)
RegisterAPIEncoderFactory adds an APIEncoderFactory by name. Panics if another factory with the same name is already registered.
Types ¶
type APIEncoder ¶ added in v1.2.1
type APIEncoder interface { EncodeGET(*Subscription) ([]byte, error) EncodePOST(json.RawMessage) ([]byte, error) EncodeError(*reserr.Error) []byte NotFoundError() []byte ContentType() string }
APIEncoder encodes responses to HTTP API requests.
type APIEncoderFactory ¶ added in v1.2.1
type APIEncoderFactory func(cfg Config) APIEncoder
APIEncoderFactory create an APIEncoder.
type Config ¶
type Config struct { Addr *string `json:"addr"` Port uint16 `json:"port"` WSPath string `json:"wsPath"` APIPath string `json:"apiPath"` APIEncoding string `json:"apiEncoding"` HeaderAuth *string `json:"headerAuth"` AllowOrigin *string `json:"allowOrigin"` PUTMethod *string `json:"putMethod"` DELETEMethod *string `json:"deleteMethod"` PATCHMethod *string `json:"patchMethod"` TLS bool `json:"tls"` TLSCert string `json:"certFile"` TLSKey string `json:"keyFile"` WSCompression bool `json:"wsCompression"` ResetThrottle int `json:"resetThrottle"` ReferenceThrottle int `json:"referenceThrottle"` NoHTTP bool `json:"-"` // Disable start of the HTTP server. Used for testing // contains filtered or unexported fields }
Config holds server configuration
type ConnSubscriber ¶
type ConnSubscriber interface { Logf(format string, v ...interface{}) Debugf(format string, v ...interface{}) Errorf(format string, v ...interface{}) CID() string Token() json.RawMessage Subscribe(rid string, direct bool, throttle *rescache.Throttle) (*Subscription, error) Unsubscribe(sub *Subscription, direct bool, count int, tryDelete bool) Access(sub *Subscription, callback func(*rescache.Access)) Send(data []byte) Enqueue(f func()) bool ExpandCID(string) string Disconnect(reason string) ProtocolVersion() int }
ConnSubscriber represents a client connection making the subscription
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a RES gateway implementation
func NewService ¶
NewService creates a new Service
func (*Service) GetWSHandlerFunc ¶
GetWSHandlerFunc returns the websocket http.Handler Used for testing purposes
func (*Service) StopChannel ¶
StopChannel returns a channel that will pass a value when the service has stopped.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a resource subscription made by a client connection
func NewSubscription ¶
func NewSubscription(c ConnSubscriber, rid string, throttle *rescache.Throttle) *Subscription
NewSubscription creates a new Subscription
func (*Subscription) CID ¶
func (s *Subscription) CID() string
CID returns the unique connection ID of the client connection
func (*Subscription) CanCall ¶
func (s *Subscription) CanCall(action string, cb func(err error))
CanCall checks asynchronously if the client connection has access to call the actionn. If access is denied, the callback will be called with an error describing the reason. If access is granted, the callback will be called with err being nil.
func (*Subscription) CanGet ¶
func (s *Subscription) CanGet(cb func(err error))
CanGet checks asynchronously if the client connection has access to get (read) the resource. If access is denied, the callback will be called with an error describing the reason. If access is granted, the callback will be called with err being nil.
func (*Subscription) CollectionValues ¶ added in v1.2.1
func (s *Subscription) CollectionValues() []codec.Value
CollectionValues returns the subscriptions collection values. Panics if the subscription is not a loaded collection.
func (*Subscription) Dispose ¶
func (s *Subscription) Dispose()
Dispose removes any resourceSubscription and sets the subscription state to stateDisposed
func (*Subscription) Error ¶
func (s *Subscription) Error() error
Error returns any error that occurred when loading the subscribed resource.
func (*Subscription) Event ¶
func (s *Subscription) Event(event *rescache.ResourceEvent)
Event passes an event to the subscription to be processed.
func (*Subscription) GetRPCResources ¶
func (s *Subscription) GetRPCResources() *rpc.Resources
GetRPCResources returns a rpc.Resources object. It will lock the subscription and queue any events until ReleaseRPCResources is called.
func (*Subscription) IsReady ¶ added in v1.2.1
func (s *Subscription) IsReady() bool
IsReady returns true if the subscription and all of its dependencies are loaded.
func (*Subscription) IsSent ¶
func (s *Subscription) IsSent() bool
IsSent returns true if the subscribed resource has been sent to the client.
func (*Subscription) Loaded ¶
func (s *Subscription) Loaded(resourceSub *rescache.ResourceSubscription, err error)
Loaded is called by rescache when the subscribed resource has been loaded. If the resource was successfully loaded, err will be nil. If an error occurred when loading the resource, resourceSub will be nil, and err will be the error.
func (*Subscription) ModelValues ¶ added in v1.2.1
func (s *Subscription) ModelValues() map[string]codec.Value
ModelValues returns the subscriptions model values. Panics if the subscription is not a loaded model.
func (*Subscription) OnReady ¶ added in v1.2.1
func (s *Subscription) OnReady(cb func())
OnReady gets a callback that should be called once the subscribed resource and all its referenced resources recursively, has been loaded from the rescache. If the resource is already ready, the callback will directly be called.
func (*Subscription) RID ¶
func (s *Subscription) RID() string
RID returns the subscription's resource ID
func (*Subscription) Reaccess ¶
func (s *Subscription) Reaccess(t *rescache.Throttle)
Reaccess adds a reaccess event to the eventQueue, triggering a new access request to be sent to the service.
func (*Subscription) Ref ¶ added in v1.2.1
func (s *Subscription) Ref(rid string) *Subscription
Ref returns the referenced subscription, or nil if subscription has no such reference.
func (*Subscription) ReleaseRPCResources ¶
func (s *Subscription) ReleaseRPCResources()
ReleaseRPCResources will unlock all resources locked by GetRPCResource, unqueue any events, and mark the subscription as sent.
func (*Subscription) ResourceName ¶
func (s *Subscription) ResourceName() string
ResourceName returns the resource name part of the subscription's resource ID
func (*Subscription) ResourceQuery ¶
func (s *Subscription) ResourceQuery() string
ResourceQuery returns the query part of the subscription's resource ID
func (*Subscription) ResourceType ¶
func (s *Subscription) ResourceType() rescache.ResourceType
ResourceType returns the resource type of the subscribed resource
func (*Subscription) Token ¶
func (s *Subscription) Token() json.RawMessage
Token returns the access token held by the subscription's client connection