Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnbsd/bun.go
A no-nonsense ("bring your own toppings") framework for building services on top of NATS.
https://github.com/dnbsd/bun.go
framework microservices nats rpc
Last synced: 18 days ago
JSON representation
A no-nonsense ("bring your own toppings") framework for building services on top of NATS.
- Host: GitHub
- URL: https://github.com/dnbsd/bun.go
- Owner: dnbsd
- License: mit
- Created: 2024-02-16T07:15:44.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-02T19:03:01.000Z (7 months ago)
- Last Synced: 2024-11-02T01:23:42.832Z (2 months ago)
- Topics: framework, microservices, nats, rpc
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# bun.go
[![GoDoc][GoDoc-Image]][GoDoc-Url]
[GoDoc-Image]: https://img.shields.io/badge/GoDoc-reference-007d9c
[GoDoc-Url]: https://pkg.go.dev/github.com/dnbsd/bun.goA no-nonsense ("bring your own toppings") framework for building services on top of NATS. Inspired by popular HTTP frameworks
[echo](https://github.com/labstack/echo) and [gin](https://github.com/gin-gonic/gin).## Installation
```
go get github.com/dnbsd/bun.go
```## Usage
### Request/Reply handling
```go
import "github.com/dnbsd/bun.go"b := bun.New(bun.Arguments{
Servers: []string{
"localhost",
}
})b.Subscribe("rpc.users.create", func(c *bun.Context){
type request struct {
Username string `json:"username"`
Password string `json:"password"`
}
type response struct {
ID uint64 `json:"id"`
}var r request
if err := c.BindJSON(&r); err != nil {
return c.Error(err)
}//
// Do things with request
//return c.JSON(response{
ID: 1,
})
})
```### Connection event handling
```go
import "github.com/dnbsd/bun.go"b := bun.New(bun.Arguments{
Servers: []string{
"localhost",
}
})b.ConnectedHandler = func(nc *nats.Conn) {
println("connected")
}
b.ReconnectedHandler = func(nc *nats.Conn) {
println("reconnected")
}
b.DisconnectedHandler = func(nc *nats.Conn, err error) {
println("disconnected")
}
```### Stream handling
```
JetStream support is currently a work in progress.
```## License
MIT