Documentation ¶
Index ¶
- func AuthLink(link string) (userID, linkID string, status int)
- func Connect(w http.ResponseWriter, r *http.Request, allowedOrigin ...string)
- func GetIP(r *http.Request) (ip string, err error)
- func Init(options ...Options)
- func IsCtxt(v any) bool
- func IsDnetContext(v any) bool
- func IsEContext(v any) bool
- func LastSeen(handler ActionHandler)
- func NewLink(userID, linkID string, minutes ...time.Duration) (link string, err error)
- func On(action string, handlers ...ActionHandler)
- func SendTicket(r *http.Request, w http.ResponseWriter, ID string)
- func Use(handlers ...ActionHandler)
- type ActionHandler
- type Ctx
- func (c *Ctx) All(statusAndData ...interface{})
- func (c *Ctx) AuthTicket(infoText ...string) (ID string, ok bool)
- func (c *Ctx) Bind(v interface{}) (err error)
- func (c *Ctx) Binder(v interface{}, msg ...string) (ok bool)
- func (c *Ctx) Broadcast(statusAndData ...interface{})
- func (c *Ctx) Clear()
- func (c *Ctx) CreateRoom(roomID string, usersIDS ...string)
- func (c *Ctx) Del(key string)
- func (c *Ctx) Dispose()
- func (c *Ctx) Fire(action string)
- func (c *Ctx) Get(key string) (val interface{}, err error)
- func (c *Ctx) Logout()
- func (c *Ctx) MarkAuthed(ID string)
- func (c *Ctx) Multicast(userIDs []string, statusAndData ...interface{})
- func (c *Ctx) Next()
- func (c *Ctx) Refire()
- func (c *Ctx) RoomAll(ID string, statusAndData ...interface{})
- func (c *Ctx) RoomBroadcast(ID string, statusAndData ...interface{})
- func (c *Ctx) Rooms(roomsIDs ...string)
- func (c *Ctx) Send(ID string, statusAndData ...interface{})
- func (c *Ctx) SendBack(statusAndData ...interface{})
- func (c *Ctx) SendMe(statusAndData ...interface{})
- func (c *Ctx) Set(key string, val interface{})
- type DnetContext
- type EContext
- type Hub
- type MainRouter
- type Map
- type Options
- type Subrouter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthLink ¶
AuthLink validates and authenticates verification link.
link: represents the link from the client generated by the Link () function. It returns user ID if succeeds.
status: indicates the results of the link validation. Where,
0 means link expired
1 stands for bad request i.e client side has sent the wrong link
2 means everything is fine! and with this status you can get the user ID.
func Connect ¶
func Connect(w http.ResponseWriter, r *http.Request, allowedOrigin ...string)
Connect inits connection in the given endpoint
func Init ¶
func Init(options ...Options)
Init initializes dnet hub monitoring. You should pass your configurations in this function if you are using v1.0.208-beta and above. Otherwise you should stick with Config() function
It should be called only once
func IsDnetContext ¶ added in v1.3.0
IsDnetContext tests the given value v if it's a dnet context i.e dnet.EContext or dnet.Ctx
func IsEContext ¶ added in v1.2.0
IsEContext tests the given value v if it's an external context - EContext
func LastSeen ¶
func LastSeen(handler ActionHandler)
LastSeen is called when the authenticated user gets offline or logs out It's very useful for setting the last seen of the user connection
func NewLink ¶
NewLink generates a link to use for user verification.
ID is a Unique identifier stored in the link througth aes encryption.
minutes is a life time of the link in minutes i.e after that amount of time the link becomes expired. Default time is 60 minutes
func On ¶
func On(action string, handlers ...ActionHandler)
On method takes ActionHandlers to be called when the given action fired by the dnet-client
func SendTicket ¶
func SendTicket(r *http.Request, w http.ResponseWriter, ID string)
SendTicket sends an encrypted ticket to the user.
func Use ¶
func Use(handlers ...ActionHandler)
Use adds root-level middlewares which will be called before any action is matched.
Types ¶
type Ctx ¶ added in v1.0.71
type Ctx struct { //ID of the user owning the connection ID string // Rec is an id of the recipient Rec string // Authed tells if the connection is authenticated or not Authed bool // IP address of the connection IP string // contains filtered or unexported fields }
Ctx is a middleman between the websocket connection and the Hub. Ctx is stored in the dnet hub and hence it is an inside and persistent context.
func ToCtx ¶ added in v1.3.0
ToCtx converts the given value v to *dnet.Ctx.
ok is returned when the assertion succeed
func (*Ctx) All ¶ added in v1.0.71
func (c *Ctx) All(statusAndData ...interface{})
All sends to anyone connected to the websocket Dnet instance including the sender of the message
func (*Ctx) AuthTicket ¶ added in v1.0.71
AuthTicket authenticates the ticket and returns the user ID provided in the SendTicket().
ok is also returned to inform you if user authentication fails or not. If failed you, all you can do is simply "return" to finish your reponse cycle since AuthTicket helps you to respond to the client with the infoText you provide or the default infoText
Infotext is a message to send back to the client when user authentication fails. It defaults to "Please login to access this resource" if you do not provide it.
func (*Ctx) Bind ¶ added in v1.5.0
Bind extracts raw data, stores it in the passed pointer v and returns any raised error
func (*Ctx) Binder ¶ added in v1.0.71
Binder extracts raw data, stores it in the passed pointer v and implicitly sends 422 Unprocessable entities to the client when it's unable to decode data. You can provide a custom client error message by passing it as msg argument. In addition to sending a client friendly error to the client it also logs a raised error in console
It returns true on success and false on failure. You can use this value to stop the execution in the caller function by just using a return statement.
Use Bind(v interface{}) if you want to explicitly handle errors
func (*Ctx) Broadcast ¶ added in v1.0.71
func (c *Ctx) Broadcast(statusAndData ...interface{})
Broadcast sends data to all execept the sender
func (*Ctx) Clear ¶ added in v1.4.1
func (c *Ctx) Clear()
Clear empties context values. That is, deletes every value in the context values and resets the value store anew.
func (*Ctx) CreateRoom ¶ added in v1.0.71
CreateRoom is for creating a new room.... if it finds a room exist it only adds the given the room
func (*Ctx) Dispose ¶ added in v1.0.71
func (c *Ctx) Dispose()
Dispose discards the client connection without calling LastSeen for saving any lastSeen info for the clinet connection Useful for expired unauthorized client connections
func (*Ctx) Fire ¶ added in v1.0.71
Fire sets which action to fire to the client. It's recommended to keep the action in path form to maintain maintain uniformity, If you do not set the action to fire, the action you listened for it will be fired backward to the client too.
func (*Ctx) Logout ¶ added in v1.0.71
func (c *Ctx) Logout()
Logout calls the LastSeen function to ensure user last seen data is saved before discarding the client connection
func (*Ctx) MarkAuthed ¶ added in v1.1.0
MarkAuthed marks this connection as authenticated. Hence, no ticket authentication required.
Use this when you have your own authentication mechanism or just for testing purposes.
func (*Ctx) Multicast ¶ added in v1.0.71
Multicast sends to the given users IDs (useful for sharing something to multiple users
func (*Ctx) Next ¶ added in v1.0.71
func (c *Ctx) Next()
Next pushes the next middleware in the list
func (*Ctx) Refire ¶ added in v1.5.0
func (c *Ctx) Refire()
Refire resets action to the initial action before calling any Fire("/action") method. In fact, the action becomes the same as it was fired by the client.
func (*Ctx) RoomAll ¶ added in v1.0.71
RoomAll sends to the members of the room. (useful for chat rooms.. and sending data to all people under the same role or cartegory )
func (*Ctx) RoomBroadcast ¶ added in v1.0.71
RoomBroadcast sends to all members of the registered room except the sender
func (*Ctx) SendBack ¶ added in v1.0.71
func (c *Ctx) SendBack(statusAndData ...interface{})
SendBack sends back to the sender's sending connection only.
Use sendMe() if you want to send to all of the sender's connections including the sending connection.
type DnetContext ¶ added in v1.4.0
type EContext ¶ added in v1.0.71
type EContext struct { //ID is a user id to assocaite it with the user connection ID string // contains filtered or unexported fields }
EContext is an external context which provides functionalities for sending data to the websocket's connections from a normal http connection. It interfaces the dnet hub and dnet sending functionalities to the normal http connection. EContext is not stored inside the dnet hub and hence it is called external and immidiate context.
func Context ¶
Context creates an external context for sending data to the websocket connections from a normal http connection.
func ToEContext ¶ added in v1.3.0
ToEContext converts the given value v to *dnet.EContext.
ok is returned when the assertion succeed
func (*EContext) Broadcast ¶ added in v1.0.71
func (c *EContext) Broadcast(statusAndData ...interface{})
Broadcast sends data to alll dnet contexts in the hub
func (*EContext) Fire ¶ added in v1.0.71
Fire sets which action to fire to the client. It's recommended to keep the action in path form to maintain maintain uniformity, If you do not set the action to fire, the action you listened for it will be fired backward to the client too.
func (*EContext) Multicast ¶ added in v1.0.71
Multicast sends to the given users IDs (useful for sharing something to multiple users
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains and manages dnet contexts
type MainRouter ¶
type MainRouter struct {
// contains filtered or unexported fields
}
MainRouter routes websocket actions
func (*MainRouter) Route ¶
func (r *MainRouter) Route(IncomingAction string, context *Ctx)
Route performs routing websocket actions based on the incoming action
type Map ¶
type Map map[string]interface{}
Map models json data to be sent to the client by creating a map[string]interface{}
type Subrouter ¶ added in v1.1.0
type Subrouter struct {
// contains filtered or unexported fields
}
Subrouter is for grouping actions, and creating middleware subjected to the particular group
func (Subrouter) On ¶ added in v1.1.0
func (r Subrouter) On(action string, handlers ...ActionHandler)
On method is adding Event handlders to the router by prefixing it with the Matcher path
func (*Subrouter) Use ¶ added in v1.1.0
func (r *Subrouter) Use(handlers ...ActionHandler)
Use adds middlewares to the subrouter which will be called before any other subrouter actions