gossiper
is a modern Go library designed to simplify server management and transport mechanisms for gRPC, REST, and RabbitMQ in distributed systems. The package allows developers to manage servers, routes, and database connections with ease, while supporting a pluggable architecture for extending functionality.
go get github.com/pieceowater-dev/lotof.lib.gossiper/v2
Features
- Centralized server management with ServerManager
- Support for gRPC and REST servers
- RabbitMQ server integration
- Transport factory for creating gRPC-based communication channels
- Simplified database connection management
- Modular and extendable design
gossiper provides a ServerManager to manage multiple servers, such as gRPC and REST, in one place.
package main
import (
"github.com/gin-gonic/gin"
"github.com/pieceowater-dev/lotof.lib.gossiper/v2"
"google.golang.org/grpc"
)
func main() {
serverManager := gossiper.NewServerManager()
// Initialize gRPC Server
grpcInitRoute := func(server *grpc.Server) {
// Define gRPC services here
}
serverManager.AddServer(gossiper.NewGRPCServ("50051", grpc.NewServer(), grpcInitRoute))
// Initialize REST Server
restInitRoute := func(router *gin.Engine) {
router.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
}
serverManager.AddServer(gossiper.NewRESTServ("8080", gin.Default(), restInitRoute))
// Start all servers
serverManager.StartAll()
defer serverManager.StopAll()
}
The TransportFactory simplifies the creation of transport mechanisms for communication, such as gRPC.
Example: Creating a gRPC Transport
package main
import (
"github.com/pieceowater-dev/lotof.lib.gossiper/v2"
)
func main() {
factory := gossiper.NewTransportFactory()
grpcTransport := factory.CreateTransport(
gossiper.GRPC,
"localhost:50051",
)
// Use grpcTransport to send requests or create clients
_ = grpcTransport
}
Manages the lifecycle of multiple servers (start, stop).
- NewServerManager Creates a new server manager instance.
- AddServer Adds a new server (e.g., gRPC, REST) to the manager.
- StartAll / StopAll Starts or stops all servers managed by the instance.
gRPC Server
- NewGRPCServ Creates a new gRPC server instance.
REST Server
- NewRESTServ Creates a new REST server using the Gin framework.
RabbitMQ Server
- NewRMQServ Creates a new RabbitMQ server instance.
TransportFactory
The TransportFactory provides a unified way to create communication transports.
- Supported Transports:
- GRPC: For gRPC communication.
factory := gossiper.NewTransportFactory()
transport := factory.CreateTransport(gossiper.GRPC, "localhost:50051")
Initializes a database connection.
- Supported Database Types:
- PostgresDB: For PostgreSQL connections.
db, err := gossiper.NewDB(gossiper.PostgresDB, "your-dsn", true)
if err != nil {
panic(err)
}
Contributions are welcome! Feel free to submit issues or pull requests to improve the package or its documentation.
With gossiper
, managing RabbitMQ consumers and environment variables in Go projects becomes more straightforward. Enjoy using it!
This project is licensed under the MIT License - see the LICENSE file for details.