Documentation
¶
Overview ¶
Package hibiraecho connects Hibira to Echo (v5): channel authorization and user sign-in endpoints for pusher-js, webhook and Approvals callback receivers, and a waiting room middleware. Your functions get the *echo.Context, so whatever your auth middleware stored there is at hand.
client := hibira.FromEnv()
e := echo.New()
g := e.Group("/hibira", requireLogin)
g.POST("/auth", hibiraecho.Auth(client, func(c *echo.Context, channel string) (bool, *hibira.Member) {
u := c.Get("user").(*User)
if channel == "private-user-"+u.ID {
return true, nil
}
return strings.HasPrefix(channel, "presence-room-"), &hibira.Member{UserID: u.ID, UserInfo: map[string]string{"name": u.Name}}
}))
g.POST("/user-auth", hibiraecho.UserAuth(client, func(c *echo.Context) *hibira.User {
return &hibira.User{ID: c.Get("user").(*User).ID}
}))
e.POST("/hibira/webhook", hibiraecho.Webhook(client, onWebhook))
e.GET("/drop", dropPage, hibiraecho.WaitingRoom(room))
On Echo v4, mount the net/http handlers of github.com/hibira-io/go with echo.WrapHandler and waitingroom.Guard.Middleware with echo.WrapMiddleware.
Index ¶
- Constants
- func ApprovalCallback(secret string, fn func(c *echo.Context, e *approvals.Event) error) echo.HandlerFunc
- func Auth(client *hibira.Client, ...) echo.HandlerFunc
- func Pass(c *echo.Context) *waitingroom.Pass
- func UserAuth(client *hibira.Client, fn func(c *echo.Context) *hibira.User) echo.HandlerFunc
- func WaitingRoom(g waitingroom.Guard) echo.MiddlewareFunc
- func Webhook(client *hibira.Client, fn func(c *echo.Context, hook *hibira.Webhook) error) echo.HandlerFunc
Constants ¶
const PassKey = "hibira.pass"
PassKey is the echo.Context key WaitingRoom stores the visitor's pass under.
Variables ¶
This section is empty.
Functions ¶
func ApprovalCallback ¶
func ApprovalCallback(secret string, fn func(c *echo.Context, e *approvals.Event) error) echo.HandlerFunc
ApprovalCallback receives Approvals decisions sent to a request's callback_url (or a workspace webhook, with its apwh_ secret). secret is the app secret for callback_url deliveries.
func Auth ¶
func Auth(client *hibira.Client, fn func(c *echo.Context, channel string) (bool, *hibira.Member)) echo.HandlerFunc
Auth answers pusher-js channel authorization requests. fn decides whether the request's user may subscribe to channel, and for presence- channels returns the member to show.
func Pass ¶
func Pass(c *echo.Context) *waitingroom.Pass
Pass returns the waiting room pass WaitingRoom let through, or nil.
func UserAuth ¶
UserAuth answers pusher-js user sign-in requests (pusher.signin()), which the Chat API and server-to-user events need. fn returns the signed-in user, or nil to refuse.
func WaitingRoom ¶
func WaitingRoom(g waitingroom.Guard) echo.MiddlewareFunc
WaitingRoom lets only visitors with a valid waiting room pass through; others go to the hosted queue page (requests other than GET or HEAD get 403). Read the pass with Pass.
Types ¶
This section is empty.