https://github.com/zapling/cone
A generic event/queue consumer with an http.Server-like interface.
https://github.com/zapling/cone
Last synced: 11 days ago
JSON representation
A generic event/queue consumer with an http.Server-like interface.
- Host: GitHub
- URL: https://github.com/zapling/cone
- Owner: zapling
- Created: 2024-09-12T13:16:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T09:42:50.000Z (8 months ago)
- Last Synced: 2025-10-18T07:03:32.744Z (3 months ago)
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cone 🗼
The goal of `cone` is to provide an easy to use event handler implementation
that can support a multitude of event backends.
---
### Table of contents
- [Usage](#usage)
- [Middleware](#middleware)
- [Todo](#todo)
---
# Usage
```go
// Configure handlers
h := cone.NewHandlerMux()
h.HandleFunc("event.subject", func(r cone.Response, e *cone.Event) {
_ = r.Ack()
})
h.HandleFunc("event.subject2", func(r cone.Response, e *cone.Event) {
_ = r.Ack()
})
// Setup an event source
s := conetest.NewSource()
// Setup consumer with source and handler
c := cone.New(s, h)
// Start consumer. Processes events from the source and calls your handler.
c.ListenAndConsume()
```
# Middleware
Middleware can be placed around a specific handler.
```go
middleware := func(next cone.Handler) cone.Handler {
return func(r cone.Response, e *cone.Event) {
next.Serve(r, e)
}
}
var handler cone.HandlerFunc = func(r cone.Response, e *cone.Event) {
_ = r.Ack()
}
h := cone.NewHandlerMux()
h.Handler("event.subject", middleware(handler))
```
Or the whole mux.
```go
middleware := func(next cone.Handler) cone.Handler {
return func(r cone.Response, e *cone.Event) {
next.Serve(r, e)
}
}
s := conetest.NewSource()
h := cone.NewHandlerMux()
c := cone.New(s, middleware(h))
```
# Todo
- [X] Event context
- [X] Event headers
- [X] Handler middleware
- [ ] Consumer subject wildcard `event.*`
- [ ] Source benchmark (Jetstream)