hibiraecho

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Hibira for Echo

github.com/hibira-io/echo 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 callbacks get Echo's own context, so whatever your auth middleware stored there is at hand.

go get github.com/hibira-io/echo

Go 1.25 or later. The core client is github.com/hibira-io/go; this module adds only the Echo glue.

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.POST("/hibira/approvals", hibiraecho.ApprovalCallback(os.Getenv("HIBIRA_APP_SECRET"), onDecision))

room := waitingroom.Guard{AppKey: os.Getenv("HIBIRA_APP_KEY"), Secret: []string{os.Getenv("HIBIRA_APP_SECRET")}, Room: "presale"}
e.GET("/drop", func(c *echo.Context) error {
	return c.String(200, fmt.Sprintf("Your number: %d", hibiraecho.Pass(c).Number))
}, hibiraecho.WaitingRoom(room))
Function Does
Auth(client, fn) Answers pusher-js channel authorization (channelAuthorization.endpoint). fn returns whether the user may subscribe, and the member for presence- channels.
UserAuth(client, fn) Answers user sign-in (pusher.signin()), which the Chat API and server-to-user events need. fn returns the user, or nil.
Webhook(client, fn) Verifies webhook deliveries (401 when forged) and passes them to fn; an error from fn answers 500 so the delivery is retried.
ApprovalCallback(secret, fn) Verifies Approvals callback_url deliveries (Hibira-Signature) and passes the decision to fn.
WaitingRoom(guard) Sends visitors without a pass to the hosted queue page (403 for requests other than GET or HEAD); Pass(c) returns the pass.

Stream LLM output from a handler

s, _ := stream.New(ctx, client, "private-conversation-"+id, stream.Options{})
for delta := range deltas { // text deltas from your model SDK
	s.WriteString(delta)
}
s.Close()

See stream and the hibira-io/go README for publishing, push notifications and the Chat API.

Echo v4

Mount the net/http handlers of the core module: e.POST("/hibira/auth", echo.WrapHandler(client.AuthHandler(fn))) and echo.WrapMiddleware(room.Middleware).

Releases

Tagged vX.Y.Z and listed under Releases and in CHANGELOG.md.

Development

gofmt -l .
go vet ./...
go test -race ./...

To test against a local checkout of the core, add replace github.com/hibira-io/go => ../go to go.mod (do not commit it).

License

MIT

中文摘要

Echo v5 專用模組:頻道授權、使用者登入、webhook、Approvals callback 與等候室 middleware,callback 拿到 *echo.Context。需要 Go 1.25 以上。Echo v4 請用核心模組的 net/http handler 搭配 echo.WrapHandler。

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

View Source
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

func UserAuth(client *hibira.Client, fn func(c *echo.Context) *hibira.User) echo.HandlerFunc

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.

func Webhook

func Webhook(client *hibira.Client, fn func(c *echo.Context, hook *hibira.Webhook) error) echo.HandlerFunc

Webhook verifies Hibira webhook deliveries and passes them to fn. A forged delivery gets 401; an error from fn answers 500 so Hibira retries.

Types

This section is empty.

Jump to

Keyboard shortcuts

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